#๐ How to make it add numbers
61 messages ยท Page 1 of 1 (latest)
Hey @quaint mantle!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
@quaint mantle
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.
print("hello how old are you?")
answer_1 = input("whats ur age?: ")
if answer_1 == answer_1:
print("you are " + answer_1 + " years old")
print()
answer_2 = input("type any number: ")
if answer_2 == answer_2:
print("hello i am",str(answer_2))
you don't need if checks, if there is a case to print only when answer _1 and answer _2 becomes equal
what do you want to achieve?
age = input("What's your age?: ")
random_num = input("Type any number: ")
if age == random_num:
print(f"Match! I am also {random_num}")
else:
print("The numbers don't match.")
# according to your post title, you wanna do something like this if im not wrong
print(int(age)+int(random_num))
For that you should use int() function first because age is a integer(numbers) not string
answer_2 = input("enter a number: ")
answer_2 = int(answer_2) + 7
print(answer_2)
I wanted to add this in here
It looks much better but the best practice is โฆint(input(โenter a number:)) putting all the input inside the int function
I can learn about that and put it in there?
Okay but what are you trying to do? Your code is working tho
Type a number then it can add a number I choose
I think youll need a loop for that
Idk what loop is๐ฌ
num = int(input("enter number"))
print(num + (whatever your number is))
That would be too hardcoded
ok
What's num
age = int(input("enter a number: "))
print(age+(10))
Like this??
without the parentheses around the number so age + 10
@quaint mantle
What does parentheses mean?
Like these
( l
( ) I mean
@quaint mantle
So it would be
age = int(input("enter a number:"))
print(age + 10)
So it functions the same
yes but it PROBABL Y wont work if you do (10)
Why we need () anyways?
idk I didnt create python
U use it alot??
Np
Ok
Is python hard when u first started?
y e s
What did u do to get better?
In your case it doesnt matter if you use it inside or not its just a group expression use for clarity and more
ok
So its not important?
never knew that
Depends on what you doing
Round brackets () do 2 things:
- grouping, when you need to ensure the an expression in interpreted a particular way
- calling a function, like input()
Grouping:
in arithmetic, 2+5*3 is 2*15 i.e 30 because * (multiplication) binds tighter than + (addition)
but (2+5)*3 is 7*3 i.e. 21 because the bracket force the adition to be considered in isolation, before the multiplication.
So your print(age + (10)) groups the 10 on its own - this has no special effect, but will work. (10) is the same as 10.
Calling a function like input("hello: ") or print(9).
The word input or print is just a reference to the function. You need brackets to run the function and collect its result.
So:
name = input
just makes the variable name refer to the function which input refers to.
name = input() actually runs the input function and returns the text it collected, saving it in name.
Yo
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.