Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# PART 1 (10 minutes or less) # Students: copy the two functions below and load into Python. # TA, after a few minutes, ask
# PART 1" (10 minutes or less) # Students: copy the two functions below and load into Python. # TA, after a few minutes, ask 1) give example of input that yields Execute/test on several values. Think about differences different results, 2) give concise but general characterization of difference? def ifV1 (num) if (numS20) print ( num, ' is divisible by 2.') nun%3-0) print ( num, ' is divisible by 3.') elif def fV2 (num) print ( umis divisible by 2.) if (numS30) print ( mum, ' is divisible by 3.') # PART 2" (20 minutes) # How can we extract and print the digits of an integer using math? # Some people might know that in Python we first convert the number to a # string of digitas and then look at each character in the string. BUT, the goal # here is to do it with just math-NO STRING OPERATIONS. # HOW2 Use this approach: l. we can get last digit of an integer by using % 10 digit-: number % 10 #2. we can get a new mumber with all but the last digit via newumber number /f 10 #3. we repeat those steps until nothing's left # (First, everyone should try examples of 1 and 2 at a Python prompt. # E.g" enter 432 % 10 and 432 // 10) # In code these steps become (TAs should write out the code here, bit by bit) def printDigitsOf (number) # add code here return
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started