2021年4月9日星期五

Why am I getting this Python syntax error?

I am trying to write code that asks a user for their dog's name and age. Once they enter their dogs age (in human years), it will return the dog's age in dog's years. However, when I run the code, I get the following syntax errors. Can anyone explain why?

  1. if age >= 0:             ^  SyntaxError: invalid syntax  
  2. print(f'Your dog is' {dogAge} 'in dog years')  ^  SyntaxError: invalid syntax  

Here is my code:

name = input("What is your dog""'""s name? ")  age = int(input("How old (in years) is your dog? "))  dogAge = ((10.5*2)+((age-2)/4)      if age >= 0:      print(f'Your dog is' {dogAge} 'in dog years')    else:      print('That is not a valid number. Please enter a number greater than or equal to zero.')  
https://stackoverflow.com/questions/67029884/why-am-i-getting-this-python-syntax-error April 10, 2021 at 08:59AM

没有评论:

发表评论