0

How to print the below line in python 3.x in below format.

print ("How old are you?"),
age = input ()
print ("How tall are you ?"),
height = input ()
print ("How much do you weigh?"),
weight = input()

print("so , you're % year old, % ft tall and % kg heavy.")% (age,height,weight)

Error:-

How old are you?
35
How tall are you ?
2
How much do you weigh?
23

so , you're %x year old, %x ft tall and %x kg heavy.

Traceback (most recent call last): File "C:/Narendra/8th July Ethans Python Batch/Exercises/Python3/ex11.py", line 8, in print("so , you're %x year old, %x ft tall and %x kg heavy.")% (age,height,weight) TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

3 Answers 3

4

If you're using Python >= 3.6: Use f-string

Ex:

age = input ("How old are you?\n");

height = input ("How tall are you ?\n");

weight = input("How much do you weigh?\n");

print(f"so , you're {age} year old, {height} ft tall and {weight} kg heavy.")

or str.format

Ex:

print("so , you're {0} year old, {1} ft tall and {2} kg heavy.".format(age, height, weight))
Sign up to request clarification or add additional context in comments.

Comments

2

The format operator % works on a string, not on the entire print function, which always returns None. Also, you need to specify the format of the placeholders with specifications such as %s.

print("so , you're %s year old, %s ft tall and %s kg heavy." % (age,height,weight))

Comments

1

I'd use the .format() function like this;

age = input('How old are you? ')
height = input('How tall are you? ' )
weight = input('How much do you weigh? ')

print(("so, you're {} year old, {} ft tall and {} kg heavy").format(age,height,weight))

1 Comment

working perfect: How old are you? 23 How tall are you ? 3 How much do you weigh? 45 so, you're 23 year old, 3 ft tall and 45 kg heavy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.