#πŸ”’ whats wrong?

29 messages Β· Page 1 of 1 (latest)

gaunt storm
#

age = input("Enter your age: ")

while age == 0:
print("Invalid age ")
age = input("Enter your age: ")

print(f"You are {age} years old")

console

Enter your age: 0
You are 0 years old
PS C:\Users\Admin\Desktop\Secret Code>

tired zephyrBOT
#

@gaunt storm

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

olive garden
gaunt storm
proven mason
#

worry not. i've been pythoning for a longer time and saw no problem. was about to ask if you forgot to save

olive garden
gaunt storm
#

num = int(input("Enter your number?: "))

while num < 0 or num > 100:
print("invalid number")
num = int(input("Enter your number?: "))

print(f"your number is {num}")

tired zephyrBOT
#

Hey @gaunt storm!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
gaunt storm
#

@olive garden

#

when I type 23.4 it give me an error

olive garden
#

what does the error say?

#

errors contain useful information

gaunt storm
#

Traceback (most recent call last):
File "c:\Users\Admin\Desktop\Secret Code\first.py", line 1, in <module>
num = int(input("Enter your number?: "))
ValueError: invalid literal for int() with base 10: '23.4'
PS C:\Users\Admin\Desktop\Secret Code>

olive garden
#

if you want 23.4 to work, then you need to convert to float, not int

olive garden
#

Why do you think you need both?

torn tangle
# gaunt storm can we make both

Int is integer, whole numbers. So you get the same error as if you entered "a" instead of a number

Float is decimal numbers (stored as floating point, hence the name "float")

All ints can be represented as decimals - just with 0 after the decimal point. So you don't need both

gaunt storm
tired zephyrBOT
#

Hey @gaunt storm!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
gaunt storm
#

still error

olive garden
#

you still have int around the 2nd input

#

you only changed the first one

#

always take a moment to look over your code

#

always look at the line number

torn tangle
#

I second the

always look at the line number

Python errors are quite good (since version 3.10, if I remember correctly) - so just read them and you'll soon be able to debug the stuff yourself.
Here: the error would be the same as original one (and now you already know what it means!), but showing the second input line -> so you'd see the line and notice it still has int

tired zephyrBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.