My coding language doesnt seem to be making sense

Joined
Sep 4, 2023
Messages
2
Reaction score
0
I'll send a screenshot
Capture1.PNG
 
Joined
Jul 4, 2023
Messages
376
Reaction score
42
The error you're encountering is because the x variable is initially taken as a string when you use the input() function.
Even if you used float(x) in while float(x), because float returns a value, it does not assign the value to the variable specified as a parameter.

try
Python:
x = input("Whats your favourite number? ")

while float(x) > 1:
    x = float(x) - 1
    print(x)
or
Python:
x = float(input("Whats your favourite number? "))

while x > 1:
    x = x - 1
    print(x)
or
Python:
x = float(input("Whats your favourite number? "))

while x > 1:
    x -= 1
    print(x)
 
Joined
Jul 4, 2023
Messages
376
Reaction score
42
Check this
[ on-line ]
Python:
while True:
    try:
        x = float(input("What's your favorite number? "))
        if x <= 1:
            print("Number, bigger than 1, please.")
            continue
        break
    except:
        print("Number, please.")

while x > 1:
    x -= 1
    print(round(x, 3))
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,355
Latest member
SJLChristi

Latest Threads

Top