Python: Declare as integer and character

John picture John · Feb 26, 2017 · Viewed 60.7k times · Source
# declare score as integer
score = int

# declare rating as character
rating = chr

# write "Enter score: "
# input score
score = input("Enter score: ")

# if score == 10 Then
#   set rating = "A"
# endif
if score == 10:
    rating = "A"

print(rating)

When I execute this code and enter "10" I get, built-in function chr, in the shell. I want it to print A, or another character depending on the score. For example if the input score was 8 or 9 it would have to read B. But, I'm trying to get past the first step first. I am new to programming, and if I can get pointed in the right direction that would help a lot.

Answer

falsetru picture falsetru · Feb 26, 2017
# declare score as integer
score = int

# declare rating as character
rating = chr

Above two statement, assigns the function int, chr, not declaring the variable with the default value. (BTW, chr is not a type, but a function that convert the code-point value to character)

Do this instead:

score = 0    # or   int()
rating = ''  # or   'C'   # if you want C to be default rating

NOTE score is not need to be initialized, because it's assigned by score = input("Enter score: ")