# find temperature of a city using weather api import urllib2 import json response = urllib2.urlopen('http://api.openweathermap.org/data/2.5/weather?q=London,uk') html = response.read() # print html j = json.loads(html) kelvin = j["main"]["temp_min"] celsius = kelvin - 273 print celsius
# Guessing game # Description # The computer will pick a number between 1 and 100. (You can choose any high number you want.) The purpose of the game is to guess the number the computer picked in as few guesses as possible. # Input # The user will enter his or her guess until the correct number is guessed. # Output # The program will keep asking the user to guess until he or she gets the number correct. Then the program will print how many guesses were required. # Sample session # Time to play a guessing game. # Enter a number between 1 and 100: 62 # Too high. Try again: 32 # Too low. Try again: 51 # Too low. Try again: 56 # Congratulations! You got it in 4 guesses. from random import randint choice = randint(1,10) print choice for x in range(1,10): strin = raw_input('Enter your choice:') if int(choice) == int(strin): if x > 1: print 'you got it in ' + str(x) +' tries' break else: print 'you got it in first try' break else: print 'Keep Trying'
# Temperature converter # Description # Write two functions that will convert temperatures back and forth from the Celsius and Fahrenheit temperature scales. The formulas for making the conversion are as follows: # Tc=(5/9)*(Tf-32) # Tf=(9/5)*Tc+32 # where Tc is the Celsius temperature and Tf is the Fahrenheit temperature. More information and further descriptions of how to do the conversion can be found at this NASA Webpage. If you finish this assignment quickly, add a function to calculate the wind chill. # Input # Your program should ask the user to input a temperature and then which conversion they would like to perform. # Sample session # Temperature converter # Enter a temperature: 20 # Convert to (F)ahrenheit or (C)elsius? F # 20 C = 68 F temp = raw_input('Enter Temperature:') choice = raw_input('Convert to (F)ahrenheit or (C)elsius ?') if choice == 'F': print temp + ' C = ' + str((9*int(temp)/5)+32) + ' F' else: print temp+ ' F = ' + str((int(temp)-32)*5/9) + ' C'