Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

`else` does not show the value

I built the code below.
Code works ok when user insert word which is inside of data variable. If user type "monda" instead of "monday" then I get error message. My "else" does not apply here.
Could you please look at that and suggest me what can I correct.
Second thing is that numbers from data they should be printed on the end in print always with same shape as in data variable but friday where is 0800 it prints me 800. How can I correct the code so it shows me 0800 in print on the end.

data = """
monday;1250
tuesday;1405
wednesday;1750
thursday;1100
friday;0800
saturday;1225
sunday;1355
"""
data = data.strip()
data = {day: number for day, number in [line.split(';') for line in data.split('\n')]}
day = input("Insert day: ").lower()
number = int(data[day])
temperature = 0

if day in data:
   if number >= 1400:
       temperature = number / 22.5
   elif number >= 1200 and number <=1400:
       temperature = number / 23.1
   elif number < 1200:
       temperature = number / 23.5
else:
   print("Check day and insert again, please!")

print("""Data for "{}"\nNumber: {}\nTemperature {:.3f}\u2103""".format(day, number, temperature))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As a number, there is no difference between 800 and 0800. You must say at print time what format to use:

print("""Data for "{}"\nNumber: {:04d}\nTemperature {:.3f}\u2103""".format(day, number, temperature))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading