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... |
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
# Create a student directory by allowing the user to enter all data. | |
def create_student_directory(): | |
all_students_by_onyen = {} | |
all_students_by_email = {} | |
all_students_by_name = {} | |
# Get as many students as the user wants to enter, | |
# storing each in “students” onyen as key. | |
stud_name = input('Enter student name (enter blank line to quit): ') | |
while stud_name != '': |
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
__author__ = 'David Gotz, gotz@unc.edu, Onyen = gotz' | |
import random | |
# Simulates a random card drawing. Returns a dictionary with suit and value | |
# keys. | |
def draw_card(): | |
suit = random.choice(["Spades", "Clubs", "Diamonds", "Hearts"]) | |
value = random.randint(1,13) |