#๐Ÿ”’ How to make it add numbers

61 messages ยท Page 1 of 1 (latest)

lofty roostBOT
#

Hey @quaint mantle!

Please edit your message to use a code block

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

This will result in the following:

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

@quaint mantle

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.

quaint mantle
#

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))

eager quest
quasi axle
#

what do you want to achieve?

eager quest
#
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))
tropic pollen
quaint mantle
tropic pollen
quaint mantle
tropic pollen
#

Okay but what are you trying to do? Your code is working tho

quaint mantle
tropic pollen
#

I think youll need a loop for that

quaint mantle
plain brook
#

num = int(input("enter number"))
print(num + (whatever your number is))

tropic pollen
#

That would be too hardcoded

plain brook
#

ok

plain brook
#

variable.

#

you can replace num with anything

#

(String)

plain brook
#

or just do x, its easier

quaint mantle
#

Like this??

plain brook
#

without the parentheses around the number so age + 10

plain brook
quaint mantle
plain brook
#

Like these
( l

#

( ) I mean

#

@quaint mantle
So it would be

age = int(input("enter a number:"))
print(age + 10)

plain brook
#

yes but it PROBABL Y wont work if you do (10)

quaint mantle
plain brook
#

idk I didnt create python

quaint mantle
plain brook
#

uhhhhh

#

yes......

#

-# I dont use c++ ok?

quaint mantle
#

I will get curious alot

plain brook
#

I started python 2 years ago-

#

not to brag but just saying

quaint mantle
plain brook
#

Ok

quaint mantle
plain brook
#

y e s

quaint mantle
plain brook
#

learn.

#

and I pretty much learned while playing around with it

#

by*

tropic pollen
plain brook
#

ok

plain brook
#

never knew that

tropic pollen
#

Depends on what you doing

vital beacon
# quaint mantle Why we need () anyways?

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.

lofty roostBOT
#
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.