Cant print inch and feet symbols in function
Question:
Define a function print_feet_inch_short(), with parameters num_feet and num_inches, that prints using ‘ and " shorthand. End with a newline. Remember that print() outputs a newline by default. Ex: print_feet_inch_short(5, 8) prints:
5’ 8"
My code:
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)
When i compile my code i get 5 8
instead of 5' 8"
Please help me to get the inch and feet symbols in the function
Thanks in advance
Answers:
Try to escape it:
print("5' 8"")
or with your variables:
print(f"{num_feet}' {num_inches}"")
Cheers
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))
Try:
def print_feet_inch_short(num_feet, num_inches):
print(f"{num_feet}' {num_inches}"")
Usage:
>>> print_feet_inch_short(5, 8)
5' 8"
This worked for me
def print_feet_inch_short(num_feet, num_inches):
print(f"{num_feet}' {num_inches}"")
return print_feet_inch_short
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)
Define a function print_feet_inch_short(), with parameters num_feet and num_inches, that prints using ‘ and " shorthand. End with a newline. Remember that print() outputs a newline by default. Ex: print_feet_inch_short(5, 8) prints:
5’ 8"
My code:
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)
When i compile my code i get 5 8
instead of 5' 8"
Please help me to get the inch and feet symbols in the function
Thanks in advance
Try to escape it:
print("5' 8"")
or with your variables:
print(f"{num_feet}' {num_inches}"")
Cheers
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))
Try:
def print_feet_inch_short(num_feet, num_inches):
print(f"{num_feet}' {num_inches}"")
Usage:
>>> print_feet_inch_short(5, 8)
5' 8"
This worked for me
def print_feet_inch_short(num_feet, num_inches):
print(f"{num_feet}' {num_inches}"")
return print_feet_inch_short
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)