How to write a function that outputs a two-column table [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need help with creating a table. The question is asking me to write a function that outputs a two column table of kilogram weights and their pound equivalents for kilogram values 0, 10, 20 ..., 100.
So far I have:
kilos = eval(input("Enter a weight in kilograms: "))
pounds = 2.2 * kilos
print("The weight in pounds is", pounds)
but I have no idea how to construct this as a table.

By table I assume that you are trying to print the output on console.
mult_factor = 2.20462
print ('Kilogram', 'Pound')
for i in range (0, 100, 10):
print (i , i * mult_factor)

Related

Can i print two statements with different conditions in a single if statement in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
In this code if a person if greater than 80 he/she should be displayed with different statement whereas the one with age greater than 18 different but if possible without adding anymore if statements
if 80 > given > 18:
print("you are eligible for voting")
else:
print("you are not")
Possible to do without ifs at all!
for age in (10, 19, 50, 88):
print('age', age, 'is', ['<18', '18:80', '>80'][
int((age - 18) / (80 - 18) + 1)])
Output:
age 10 is <18
age 19 is 18:80
age 50 is 18:80
age 88 is >80

Format String - number [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This is a easy question but i need explanation.
In this code Why the output is 100:
x = 100.1205
y = str(x)[6]
print("{:.{}f}".format(x,y))
x = 100.1205
y = str(x)[6] ## This is turning x into a string and grabbing the 6th character which is 0
print("{:.{}f}".format(x,y)) # this is saying print x to the decimal place
#specified by the value of y (zeroth digit) which is 100

How to print inputs in new line [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Hey is there a way to print inputs like this:
Input:
Enter the minimum number of feet (not less than 0):
5
Enter the maximum number of feet (not more than 99):
10
How can one do this?
Simply add a new line to the input prompt with \n (Python newline character) like this:
minFeet = input("Enter the minimum number of feet (not less than 0): \n")
maxFeet = input("Enter the maximum number of feet (not more than 99): \n")
You can just do it like this:
print("Enter the minimum number of feet (not less than 0):")
minN = input()
print("Enter the maximum number of feet (not more than 99):")
maxN = input()

how to restrict user to input only upto two decimal point float numbers in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am new in python, i want to do is limit the float input by the user only upto two decimal point, eg: 1.11, user is not allowed to input 1.111 or more than to after two decimal point . Thank you
You cannot restrict what the user inputs, but you can convert a float to have 2 decimal points:
value = float(input("Input your number: "))
print ("You inputted " + str(value))
new_value = "{:.2f}".format(value)
print ("After formatting, your number has become: " + str(new_value))

Create random string with a char + 2 numbers - python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Two questions:
How to create a char+number random string. one char and 2 digit numbers
for example: U12 OR W82
How to create a random 5 digit number with no zero at the beginning: 02345 , 03243
1)
import random, string
"%c%02d" % (random.choice(string.uppercase), random.randint(0, 99))
2)
import random
random.randint(10000, 99999)

Categories

Resources