Question: Hi, I would need to code the following using Python using For and range. That is, if the user gives input 3, the program calculates
Hi,
I would need to code the following using Python using "For" and "range".
That is, if the user gives input 3, the program calculates 0+1+2, if 5 then 0+1+2+3+4. Finally, the program prints the final result to the user in the form "Accumulated:" and the answer.
Example output -------------------------------------------
Program asks user how many laps?: 5 It accumulated: 10 ------------------------------------------- The verification of program output does not account for whitespace and is not case-sensitive (the least strict comparison level)
So I did this:
int num = input("How many laps? : "); int sum = 0; values = range(num); for i in values: sum +=i; print("Accumulated " + sum);
I get an error while translating and I can't for the life of me figure out why, because the syntax on line 1 looks fine to me. Error below.
File "main.py", line 1
int num = input("How many laps? : ");
SyntaxError: invalid syntax
Any help is appreciated.
Thanks, Toni
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
