So, in my beginner python class, we were asked to perform some basic arithmetic on numbers typed by the user, basic stuff. It was supposed to return a number with 2 decimal places, but I can only get it to extend to one. If the decimal terminates at the first decimal, is there a way to add another place? If the decimal terminates later, or is infinite, is there a way to display the second number as well?
print "Please enter the month of your birthday as a number.";
print "\t Jan = 1";
print "\t Feb = 2";
print "\t Apr = 3"
print "etc, etc, etc."
num = input("\n");
day = input("What date were you born on?\n");
new = (((((((((((num * 7.0) - 1.0) * 13.0) + day) + 3.0) * 11.0) - num) - day) / 10.0) + 11.00) / 100.0);
print "You were born in the", new, "month.";
Just had to experiment for a little bit, and my solution is kind of cheating.
new = str(new) + "0";
This changes the "new" into a string, and adds an extra 0 to the float.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.