CS 303e discussion assignment
due: February 10, 2011 at the beginning of discussion
1. What is the output when the following program is executed?
def main():
number = 2512
sum = 0
sum = sum + number%10
number = number/10
sum = sum + number%10
number = number/10
sum = sum + number%10
number = number/10
sum = sum + number%10
number = number/10
sum = sum + number%10
print sum
main()
2. Suppose in #1 that number was assigned a different 4 digit positive integer. Describe in general what the output would be.
3. Write a program that prompts the user to enter two positive
integers, and then prints their sum, product and quotient (with
remainder).
Sample Run: (user inputs are underlined)
What's your first number? 4
What's your second number? 2
4 + 2 = 6
4 * 2 = 8
4 / 2 = 2 R 0
4. Read a floating point number from the user, and display it with 3
digits after the decimal point in a field of minimum width 10. Then
print it again in exponential format.