CS 115 Weekly Assignments 2

Please answer the following questions and submit the answers using this link (Choose Week assignment 2). The due date for the final submission is the midnight of Saturday June 27th. You can use any text editor that you like even the simple one.

Question 1:

Given the variable price_per_case , write an expression corresponding to the price of a dozen cases.

Question 2

a). Write a for loop that prints the integers 50 through 1, each on a separate line. Use no variables other than count.

b). Write a for loop that prints in ascending order all the positive multiples of 5 that are less than 175, each value on a separate line (There is no need to use the statements)

c). Write a loop that will print out the numbers 2 4 6 8 10 12 14 16 18. They will each appear on different lines.

Question 3

a). Write some code that reads in a name and an age into the variables name and age. It then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE represent the values read into the variables name and age respectively.

For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself. There should NOT be a period in the output.

b). Use two variables k and total to write a for loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total . Thus, your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total . Use no variables other than k and total

Question 4

a). Write a for loop that prints the integers 0 through 39, each value on a separate line.

b). Write a for loop that prints the odd integers 11 through 121 inclusive, each value on a separate line.

Question 5

a). Given this code

t = 0

for i in range(5):

t = t + i*2

What would the value of t be after the code runs?

·  18

·  20

·  30

·  0

b). In the code below, what line would cause the code to produce the number 120?

fct = 1

for ctr in range(1, 6):

what goes here?

·  fct=fct+ctr

·  fct=fct*ctr

·  fct=fct**ctr

·  fct=fct*10

Question 6

·  Use the double loop and incorporate it in your circle drawing program so that displays 5 lines of 8 circles...

Question 7

Create a program that will display this set of several 45-degree lines: