0
How can we print the code 1=1\n 1+2=3\n 1+2+3=6.... Giving an input of a certain size of the pattern
I would be glad if someone gave it as easy as possible.. This language is my worst nightmare!
1 Resposta
+ 1
---EDIT:---
I was able to make the code a little shorter and easier:
x = int(input())
if x<0:
print("Negative doesn't work...")
quit()
while x>0:
sum=0
for i in range(1,x+1):
if 0<i<x:
print(i, end= '+')
elif i==0:
quit()
elif 0<i==x:
print(i, end= '')
sum += i
x=x-1
if x==-1:
quit()
print("=", str(sum))
---PREVIOUS CODE:---
x = int(input())
if x<0:
print("Negative doesn't work...")
quit()
def nums(x):
sum=0
for i in range(1,x+1):
if i < x:
print(i, end= '+')
elif i == x:
print(i, end='')
sum += i
return sum
print()
print("=",str(nums(x)))
y=x
while y>=1:
sum=0
for i in range(1,y):
if 0<i<y-1:
print(i, end= '+')
elif i==0:
quit()
elif 0<i==y-1:
print(i, end= '')
sum += i
y=y-1
if y==0:
quit()
print("=", str(sum))
Btw, just tell me if there's something that you want me to explain, and i'll try my best to do so.