1.Modify your program by enclosing your loop in another loop so that you can fin
ID: 3570599 • Letter: 1
Question
1.Modify your program 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 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 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 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
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))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.