This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the chance of precipitation | |
def get_chance_of_precip(): | |
# Read in precip chance as a float between 0 and 1. | |
precip = -1 | |
while precip < 0 or precip > 1: | |
# Read in the chance of precip from the user. | |
precip = float(input("What is the chance of precipitation [0.0-1.0]:")) | |
return precip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_info_about_house_to_buy(): | |
bathrooms = int(input("Enter the number of baths: ")) | |
bedrooms = int(input("Enter the number of beds: ")) | |
return bedrooms, bathrooms | |
def get_comps(beds, baths): | |
return 0, 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Determines the popularity rank for name_to_fine and returns that | |
# as an integer. | |
def get_name_rank(name_to_find, name_file): | |
line = name_file.readline().rstrip('\n') | |
count = 1 | |
while (line != name_to_find) and (line != ''): | |
# Read the next line. | |
line = name_file.readline().rstrip('\n') | |
count += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validated input function for numbers 1-10. | |
# This function will ensure that numbers are: | |
# 1. Not too big | |
# 2. Not too small | |
# 3. Valid integers | |
def input_integer_1to10(): | |
user_num = None | |
while user_num == None: | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validated input function for numbers min-max. | |
# This function will ensure that numbers are: | |
# 1. Not too big | |
# 2. Not too small | |
# 3. Valid integers | |
def input_integer_in_range(prompt, min_val, max_val): | |
user_num = None | |
while user_num == None: | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_oneval_to_int(num_to_convert): | |
num_to_convert = int(num_to_convert) | |
return num_to_convert | |
def convert_vals_to_int(list_to_convert): | |
#list_to_convert = list(list_to_convert) | |
# Convert each item in the list to an integer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def query(book): | |
query_string = input("What do you want to look for?") | |
if query_string in book: | |
print("Yes, it is in the book.") | |
else: | |
print("No, it is not in the book") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import ssl | |
# Required because the Census website | |
ssl._create_default_https_context = ssl._create_unverified_context | |
# If you follow the instructions on this Stackoverflow page, you should be able to omit the line above. | |
# https://stackoverflow.com/questions/35569042/ssl-certificate-verify-failed-with-python3/43855394#43855394 | |
# | |
# Go to the folder where Python is installed, e.g., in my case it is installed in the Applications folder with the | |
# folder name 'Python 3.6'. Now double click on 'Install Certificates.command'. After that error was gone. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all_students_by_name[stud_name] = [one_student] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get university colors from the user and return as a dict | |
def get_colors(): | |
color_dict = {} | |
univ_name = input("Enter a university name (or enter to stop): ") | |
while univ_name != '': | |
univ_color = input("Enter the color: ") | |
color_dict[univ_name] = univ_color | |
# Get the next university name... |