无法在函数中打印英寸和英尺符号

Cant print inch and feet symbols in function

定义函数 print_feet_inch_short(),参数为 num_feet 和 num_inches,使用 ' 和 " shorthand 打印。以换行符结束。记住打印() 默认输出一个换行符。例如:print_feet_inch_short(5, 8) 打印: 5' 8"

我的代码:

def print_feet_inch_short(num_feet, num_inches):
    return print(num_feet , num_inches )
''' Your solution goes here '''

user_feet = int(input())
user_inches = int(input())

print_feet_inch_short(user_feet, user_inches) # Will be run with (5, 8), then (4, 11)

当我编译我的代码时,我得到 5 8 而不是 5' 8" 请帮我获取函数中的英寸和英尺符号

提前致谢

尝试逃脱:

print("5' 8\"")

或使用您的变量:

print(f"{num_feet}' {num_inches}\"")

干杯

def print_feet_inch_short(num_feet, num_inches):
    #first, you cannot use both print and return in the same line
    #here you have both examples using first the print statement
    #Also, to obtain the result you need, you should use the f" string, which formats the string
    print(f"{num_feet}' {num_inches}\"")
    #Or you can use the .format() fucntion, and you get the same result
    print("{}' {}\"".format(num_feet,num_inches))
    #and the usung the return statement
    return f"{num_feet}' {num_inches}\"" 
    
user_feet = int(input())
user_inches = int(input())

#When you call the function, only the print statement gets to run
print_feet_inch_short(user_feet, user_inches)

#that's because the return statement returns the value into the function itself
#To get the return statement to appear, you use the print statement
print(print_feet_inch_short(user_feet, user_inches))

尝试:

def print_feet_inch_short(num_feet, num_inches):
    print(f"{num_feet}' {num_inches}\"")

用法:

>>> print_feet_inch_short(5, 8)
5' 8"