0

What I am trying to do is have a skill level and have it roll a random number if the number is greater than the skill variable then the roll is fail. If it is equal to or less than half +1 then it would be a regular success. if the roll was equal to or less than 25% of the skill it would be an extreme success.

import random
min = 1
max = 100
skill = 60
roll = (random.randint(min, max))
print ("Rolling the dices...")
print (roll)
hard_skill = skill/2
extreme_success = skill * .25
regular_success <= skill and => hard_skill +1
if roll > skill:
    print (fail)
elif roll > success_skill < skill:
    print (success_skill)

Getting a syntax error on line 10:

    skill >= regular_success and => hard_skill + 1
                                 ^
SyntaxError: invalid syntax
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Nixnix
  • 3
  • 1
  • 2
  • 1
    You should not use the names of builtin functions as variable names. `min`, `max` are both built-in functions. – dawg Nov 10 '20 at 16:27
  • 1
    That looks like a very literal tranlsation of "a is less than b and greater than c", but `and` goes *between* two expressions in Python. Did you mean `skill >= regular_success >= hard_skill + 1`? – molbdnilo Nov 10 '20 at 16:29

4 Answers4

1

Python does not "remember" which variable you are talking about; if you want two comparisons, you need to write them out.

regular_success <= skill and => hard_skill +1

should be (also changing => to >=)

regular_success <= skill and regular_success >= hard_skill +1

Python does offer an abbreviation for range tests: you can write the common variable in the middle, like this:

hard_skill + 1 <= regular_success <= skill

Pick the form that seems clearer to you.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • got an error on regular_success not defined Traceback (most recent call last): File "C:\Users\ndsig\PycharmProjects\pythonProject\app.py", line 10, in regular_success <= skill and regular_success >= hard_skill +1 NameError: name 'regular_success' is not defined Rolling the dices... 31 – Nixnix Nov 10 '20 at 16:30
  • 1
    You need to fix the rest of your program, then. It's true, you never defined it here. My answer addresses the syntax error you were getting, but beyond that you need to go back to learning python and learning to code. If you get completely stuck, please ask a new question. (And please be aware that stackoverflow is not a "write my code please" kind of website; questions that are not about a specific problem get downvoted and closed.) – alexis Nov 10 '20 at 16:33
0

In python, we use >= and <= to indicate larger than and less than. In your case, you can write something like a >= b and a <= c. There are no descriptive => in Python and later part after the keyword and should be a complete comparison argument as well, i.e a >= b and a <= c is correct, but a >= b and <= c is incorrect

stickers
  • 83
  • 1
  • 6
0

As mentioned by your description that's the code to use

import random
min = 1
max = 100
skill = 60
roll = (random.randint(min, max))
print ("Rolling the dices...")
print (roll)
hard_skill = skill/2
extreme_success = skill * .25

if roll > skill:
    print ("fail")
elif(roll <= hard_skill+1):
    print ("regular success")
elif(roll <= extreme_success):
    print("Extreme sucess")

Keep in mind that some cases are not encountered yet.

Abdelrahman Emam
  • 385
  • 1
  • 6
  • 15
0

What you want is determine which "bucket" a given roll falls into:

  1. Extreme success: between 0 and skill/4
  2. Hard success: between skill/4 and skill/2
  3. Regular success: between skill/2 and skill
  4. Failure: greater than skill.

For this, you just need a single if/elif statement:

min = 1
max = 100
skill = 60
roll = (random.randint(min, max))
print ("Rolling the dices...")
print (roll)

if roll <= skill / 4:
    print("Extreme success")
elif roll <= skill / 2:
    print("Hard success")
elif roll <= skill:
    print("Success")
else:
    print("Failure")
chepner
  • 497,756
  • 71
  • 530
  • 681