Jump to content

How do i add a Variable and a number in python??

Gigabiter
Go to solution Solved by Mr_KoKa,

cool = int(input("What Number??")) + 60

here is my code:

cool=input("What Number??")
cool + 60

-------------------------------------

i just need to add "cool" plus 60, its kinda stupid but im still learning

SPECS

GPU:Msi r9 270x. PSU:corsair CX600M. CPU AMD-fx 8320. CASE: ultra etorQe mid tower. HDD:1tb barracuda.MOTHERBOARD:ASUS M5A97.

Link to comment
Share on other sites

Link to post
Share on other sites

From what I can remember, you will need code like this:

cool=int(input("What Number??"))
cool=cool + 60

if you wish to use the same variable and update it. You need the int() function since input() stores the input as a string (in my experience, this method is the easiest).

 

If you want to use a different variable name, then you can do this.

[new name here]=cool + 60 #replace [new name here] with a variable name

Forgot to add: my code is clunky, but that's how I've been taught to do it

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Gigabiter said:

here is my code:

cool=input("What Number??")
cool + 60

-------------------------------------

i just need to add "cool" plus 60, its kinda stupid but im still learning

You do it just like that.

If you want to print the output:

result = cool + 60

print(result)

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

if you need to add a number variable you can use

 

cool =+ 60 no need to wrote cool = cool + 60

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, vorticalbox said:

if you need to add a number variable you can use

 

cool =+ 60 no need to wrote cool = cool + 60

 

You have made a mistake, a =+ 2 will be equal to a = +2; which is equal to a = 2, but a += 2 is a = a + 2

Link to comment
Share on other sites

Link to post
Share on other sites

@Mr_KoKa my bad :P I was almost right though.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×