Python: Declare as integer and character

后端 未结 2 1590
无人及你
无人及你 2021-01-06 20:25
# declare score as integer
score = int

# declare rating as character
rating = chr

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

# if sc         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 21:18

    # 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: ")

提交回复
热议问题