user16188627
user16188627

Reputation:

How to get single decimal place value in Python 3

My programming class requires us to use a program that checks our code and makes sure its perfect with the example given that we are supposed to try to copy. Well my program asks for someones shoe size but it won't let me pass the lesson because I'm supposed to be able to have a decimal place at all times for the shoe size. For example you can't just have 6 you have to have 6.0. Here is my code:

name = input("Enter your name: ")
age = int(input("Enter your age: "))
size = input("Enter your shoes size: ")
siblings = input("Enter the number of siblings you have: ")
print("{} is {} years old.  They have a shoe size of {} and have {} sibling(s).".format(name, age, size, siblings))

We are using this as an intro to .format and \t and \n

Upvotes: 0

Views: 39

Answers (1)

ichramm
ichramm

Reputation: 6642

Change

print("{} is {} years old.  They have a shoe size of {} and have {} sibling(s).".format(name, age, size, siblings))

To:

print("{} is {} years old.  They have a shoe size of {:.1f} and have {} sibling(s).".format(name, age, size, siblings))

The key is in {:.1f}.

Upvotes: 1

Related Questions