Python Forum
[split] beginner and need help with python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] beginner and need help with python
#5
That looks like you've almost got it, once you correct what buran pointed out. You numbers and output just don't match up with the table given in the assignment. You want the high end (emergency) to be like line 5, with start as the number. Then you want the middle three (high, warning and ideal) to be like line 7 (so two more elif statments), with start as the low number and end as the high number. Then the else can be low.

One trick is that if you order your if/elif statement correctly, you only need to code one side of the test:

import random

num = randint(1, 4)
if num > 3:
    word = 'Four'
elif num > 2: 
    word = 'Three'
elif num > 1:
    word = 'Two'
else:
    word = 'One'

print('{} = {}'.format(num, word))
In the first elif, I know it's not greater than three, because it must have failed the if test to get to the elif test. Therefore, if it is greater than two, I know it's three, without have to make sure it's not four.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: [split] beginner and need help with python - by ichabod801 - Oct-23-2019, 07:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020