CMPT 120 LECTURE MIDTERM 1 SOLUTION

range16 1 2 3 4 5 17 what

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: is expression?: range(1,6) _[1, 2, 3, 4, 5] _________________________ 17. What is the value of this expression?: str(24+100) _'124' (string) _________________________ 18. What is the value of this expression?: int("24"+"100") _24100 (int) _________________________ 2. Programming (30-points) 19. Translate the following program using a "while" statement into an equivalent "for" statement. n=1 while n < 10: ! result = n / 2 ! print result ! for n in range(1,10): result = n / 2 print result n=n+1 20. What does the above program print (either the original or your translated version)? Show its output here: 0 1 1 2 2 3 3 4 4 21. Write a Python program that reads in your name then asks you for your age. Then the program prints "Happy Birthday <you>!" as many times as your age. Replace <you> with your actual name. # happy birthday program you = ra...
View Full Document

Ask a homework question - tutors are online