Jump to content

Help with python error

✪NaCl✪

Hello there,

For my python class i have to make a program with will ask for city and temp in fahrenheit convert it to celsius and display, But i keep getting a error and i dont know whats wrong.

Here's my code.

please help

 

>>> city=input("What city are you in?")
temp=int(input("What is the temprature?"))
nwtmp=int(temp-32)
if temp < 50:
  print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is winter")
elif temp < 65:
    print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is spring")
elif temp < 79:
    print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is fall")
elif temp > 80:
    print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is summer")
    
SyntaxError: multiple statements found while compiling a single statement

Link to comment
Share on other sites

Link to post
Share on other sites

it would help to know where the error was found. what line.

QUOTE/TAG ME WHEN REPLYING

Spend As Much Time Writing Your Question As You Want Me To Spend Responding To It.

If I'm wrong, please point it out. I'm always learning & I won't bite.

 

Desktop:

Delidded Core i7 4770K - GTX 1070 ROG Strix - 16GB DDR3 - Lots of RGB lights I never change

Laptop:

HP Spectre X360 - i7 8560U - MX150 - 2TB SSD - 16GB DDR4

Link to comment
Share on other sites

Link to post
Share on other sites

You're trying to copy/paste a script into an interactive shell. You need to go to File > New File, then put the code in there, save it, then run it.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Also, put the nwtemp*5/9 in brackets with str in front like this:

str(nwtemp*5/9) as without it the print functions wont work because it doesn't allow integers only strings

 

Link to comment
Share on other sites

Link to post
Share on other sites

You have to make a .py file and run it.

PSU Nerd | PC Parts Flipper | Cable Management Guru

Helpful Links: PSU Tier List | Why not group reg? | Avoid the EVGA G3

Helios EVO (Main Desktop) Intel Core™ i9-10900KF | 32GB DDR4-3000 | GIGABYTE Z590 AORUS ELITE | GeForce RTX 3060 Ti | NZXT H510 | EVGA G5 650W

 

Delta (Laptop) | Galaxy S21 Ultra | Pacific Spirit XT (Server)

Full Specs

Spoiler

 

Helios EVO (Main):

Intel Core™ i9-10900KF | 32GB G.Skill Ripjaws V / Team T-Force DDR4-3000 | GIGABYTE Z590 AORUS ELITE | MSI GAMING X GeForce RTX 3060 Ti 8GB GPU | NZXT H510 | EVGA G5 650W | MasterLiquid ML240L | 2x 2TB HDD | 256GB SX6000 Pro SSD | 3x Corsair SP120 RGB | Fractal Design Venturi HF-14

 

Pacific Spirit XT - Server

Intel Core™ i7-8700K (Won at LTX, signed by Dennis) | GIGABYTE Z370 AORUS GAMING 5 | 16GB Team Vulcan DDR4-3000 | Intel UrfpsgonHD 630 | Define C TG | Corsair CX450M

 

Delta - Laptop

ASUS TUF Dash F15 - Intel Core™ i7-11370H | 16GB DDR4 | RTX 3060 | 500GB NVMe SSD | 200W Brick | 65W USB-PD Charger

 


 

Intel is bringing DDR4 to the mainstream with the Intel® Core™ i5 6600K and i7 6700K processors. Learn more by clicking the link in the description below.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Fish1423 said:

Also, put the nwtemp*5/9 in brackets with str in front like this:

str(nwtemp*5/9) as without it the print functions wont work because it doesn't allow integers only strings

 

The print function accepts numbers fine.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, fizzlesticks said:

The print function accepts numbers fine.

ok then.

I started to write the code myself and it wouldn't let me do the nwtemp operation in the print statement

Thanks for correcting my mistake man :)

Link to comment
Share on other sites

Link to post
Share on other sites

You need to use code tags:

JC0ejjr.jpg

I won't help you until do. 

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Oh ok I got it working by saving it and running. Thanks.

Link to comment
Share on other sites

Link to post
Share on other sites

It sometimes immedialty crashes when I try to run it. Any ideas why?

Link to comment
Share on other sites

Link to post
Share on other sites

it doesnt show me a error the program just opens the immediatly closes

Link to comment
Share on other sites

Link to post
Share on other sites

Would not it just give me a error instead of crashing it?

Link to comment
Share on other sites

Link to post
Share on other sites

Ok so cmd prompt run type in program name? I 

Link to comment
Share on other sites

Link to post
Share on other sites

So say it was on my desktop and named w what would I type

Link to comment
Share on other sites

Link to post
Share on other sites

C:\Users\Ray-Gaming\Desktop>python [d.py]
'python' is not recognized as an internal or external command,
operable program or batch file.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, ✪NaCl✪ said:

elif temp < 79:
    print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is fall")
elif temp > 80:
    print("You are in",city,"The temprature is",nwtmp*5/9,"celsuis and it is summer")

with this code if you input 79 it would not do anything. You should change the last one to else. 

 

why do you set nwtmp and then do maths to it in the string? You should just do it when you set it.

 

printing will look much better if you do something like this


print("You are in {0}. The temperature is {1}".format(city, nwtmp*5/9))

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

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for the info I just started today. But when I try and run the program it immediately crashes

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

×