30 likes | 139 Views
Practice 1. What does this code do? message = input("Please enter text: ") for i in range(0, len (message), 1): print i , ":", message[ i ]. Practice 2. Write a code to calculate 1+2+3+….+n (where n is a number that the user inputs). Solution.
E N D
Practice 1 • What does this code do? message = input("Please enter text: ") for i in range(0, len(message), 1): print i, ":", message[i]
Practice 2 • Write a code to calculate 1+2+3+….+n (where n is a number that the user inputs)
Solution n = int(raw_input("enter a number: ")) add = 0 for num in range(n + 1): add += num #write this loop using a while loop print "the sum is", add