+ 3
Help… what did I do wrong this time?
Hey everyone… I was trying to do one of the assignments for the while loop section. I have tried several ways, and I left it with what I thought was my best attempt. I don’t understand why I am getting an error.
11 ответов
+ 7
AniZaTo ,
> the condition in the loop header is not correct. since we wanted to print all numbers including 1, it should be:
while number > 0:
...
> the parameter in the print() function should only be the *variable name*, no quotes in this case:
print(number)
> general: use *indentation with 4 spaces*, this improves the readability of the code.
+ 4
AniZaTo ,
difficult to guess what your current code is.
> please link the latest version of your code here.
+ 2
AniZaTo
1. We ask for user input to be number
2. We create a loop to print and decrease the number until a condition is met
3. We print out the number
4. We decrease the number by 1
number = int(input())
while number >= 0:
print(number)
# Same as number = number - 1
number -= 1
+ 1
AniZaTo Can you share your attempt or explain the assignement so we can see
+ 1
AniZaTo What is the program supposed to be doing for the assignment?
0
I tried but I failed miserably. I have to post it on here directly. Sorry, I know I have done it before, but I cannot find the damn file on my Ipad no matter how many times I save it ‘correctly’ I cannot find it under My code Bits when trying to share.
The excercise in question is: Time’s Up!
# take the number as input
number = int(input())
#use a while loop for the countdown
while number > 4:
print(number)
number = number -1
0
So the instruction reads:
Create a timer that will take the number of seconds as input, and countdown to 0.
Number + 3
3
2
1
0
(I switched the print command without quotation marks, but it still yealds no results) NO OUTPUT
0
number = int(input())
while number>-1
print(number)
number = number+1
0
What did you write now?
0
AniZaTo Replace the input statements with hardcoded values and errors are gone, so i think the problem is that your code ask 2 times for an input, which sololearn (at least mobile version) actually does not support 😅
you must insert all your input values in the input dialog and separate multiple values by a new
so suppose you have this simple code that will sum 2 number a and b
a = input()
b = input()
print(a,'+',b,'=',a+b)
so you must insert your numbers as following in the input dialog that appears when we first execute our code
15
12
so now, sololearn will make 15 as the value of a and 12 as the value of b
Remember this is just a sololearn behavior ☺️
0
Hii