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
478
Reaction score
60
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
478
Reaction score
60
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

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top