1.Write Python code that reads a temperature and prints a message indicating whe
ID: 3563191 • Letter: 1
Question
1.Write Python code that reads a temperature and prints a message indicating whether the temperature is above, below, or at the freezing point of water. Input consists (on a single line) of a number, followed by a space, followed by F or C (F means Fahrenheit, and C means Celsius). For example:
2.Write Python code that reads a sequence of positive integers from the console (not in the form of a list). The end of the sequence is indicated with the number -1. The user enters one number per line. The program prints the two largest numbers in the input. For example:
3.Write Python code that prompts a user to type a word. The program then prints the word backwards. For example:
4.Write Python code that prompts a user to enter (i) a list of integers, and (ii) a single integer (let's call it x). The program prints the numbers in the list that are greater than or equal to x. For example:
5.Every book that is published is assigned a unique ISBN (International Standard Book Number). All ISBNs consist of 13 digits, possibly with one or more hyphens mixed in. For example, the ISBN of the Perkovic textbook is 978-0470618462. The last digit in any ISBN is called a "check digit" and is calculated with a formula based on the previous 12 digits. In particular, the check digit is calculated as follows:
c = (10 - (?(di * wi)) % 10) % 10
where di denotes the ith digit in the ISBN and ranges from 1-12, and wi is the weight of digit i. wi = 1 for odd i, and 3 for even i. For example, the check digit for your text's ISBN is:
(10 - (9
Explanation / Answer
Solution 1
tmp = raw_input("Enter a temperature, in the form of a number followed by F or C with space");
abc=[int(s) for s in tmp.split() if s.isdigit()]
temp=int(abc[0])
if s=="C" :
temp_final= 9.0/5.0 * temp + 32
else:
temp_final=temp
if temp_final > 32:
print ("is above freezing")
elif temp_final < 32:
print ("is below freezing")
else:
print ("is at freezing")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.