-3

So user should choose between A, B or C and it should put that value into the random int

Error message: ValueError: invalid literal for int() with base 10: 'A'

option=input()
A=a=100
B=b=150
C=c=200

value=random.randint(0,int(option))
print(value)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • You're evaluating `int("A")`; did you expect the string `"A"` to get magically turned into the value assigned to the identifier `A`? If so, see e.g. https://stackoverflow.com/q/1373164/3001761. – jonrsharpe Dec 30 '19 at 18:21
  • `A` and `a` are variable names, but a random string entered by a user is not going to be taken as a variable. Imagine if Joe Hacker could just type in `password` and see your password printed out! – Martijn Pieters Dec 30 '19 at 18:23
  • So what you have is *just a string value*, not one of the variables that happen to have the same name. – Martijn Pieters Dec 30 '19 at 18:23
  • So what you *want* to do is create a dictionary: `values = {"a": 100, "b": 150, "c": 200}`. The keys of that dictionary are strings *too*. Then just use `values[option.lower()]` to first turn the user input into lowercase text, then using that lower-case text as a key to give you the the value. `'A'` becomes `'a'` becomes `100`. – Martijn Pieters Dec 30 '19 at 18:25

1 Answers1

0

Your input 'A' and try to parse it as an int with int(option) this can't work, you need the translation part form the letter to the value, a dict could be a good solution

choices = {'a': 100, 'b': 150, 'c': 200}
option = input("Choose in " + ",".join(map(str, choices.items()))) # Choose in ('a', 100),('b', 150),('c', 200)


value = random.randint(0, choices[option.lower()])
print(value)
azro
  • 53,056
  • 7
  • 34
  • 70