Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Modify your program in python by enclosing your loop in another loop so that y

ID: 3570600 • Letter: 1

Question

1.Modify your program in python by enclosing your loop in another loop so that you can find consecutive sums. For example , if 5 is entered, you will find five sum of consecutive numbers:

1 = 1
1+2 = 3
1+2+3 =6
1+2+3+4 =10
1+2+3+4+5 =15

Print only each sum, not the arithmetic expression

2. Decision Structures and Boolean Logic

1. Write an if statement in python that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.
2. Write an if statement in python that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.
3. Write an if-else statement in python that assigns 0 to the variable b if the variable a is less than 10.
Otherwise, it should assign 99 to the variable b.

Explanation / Answer

k=int(raw_input("enter the number :"))
sum=0
for i in range(1,k+1):
for j in range(1,i+1):
sum=sum+j
print(sum)
sum=0

2nd ANswer

x=101
if x>100:
y,z=20,40;
print("y=%s" %str(y))
print("z=%s" %str(z))
a=9
if a<10:
b,c=0,1
print("b=%s" %str(b))
print("c=%s" %str(c))
if a<10:
b=10
else:
b=99
print("b=%s" %str(b))