Reversed Numbers

num = ["one", "two", "three", "four", "five", "six"]
numC = 0k
for x in reversed(num):
    if numC-2<len(num):
        print("- num[",numC,"]", x, type(num[numC]))
        numC += 1
- num[ 0 ] six <class 'str'>
- num[ 1 ] five <class 'str'>
- num[ 2 ] four <class 'str'>
- num[ 3 ] three <class 'str'>
- num[ 4 ] two <class 'str'>
- num[ 5 ] one <class 'str'>

New Record and Input record

import getpass, sys

InfoDb = []


InfoDb.append({
    "FirstName": "John",
    "LastName": "Mortensen",
    "DOB": "October 21",
    "Residence": "San Diego",
    "Email": "jmortensen@powayusd.com",
    "Owns_Cars": ["2015-Fusion", "2011-Ranger", "2003-Excursion", "1997-F350", "1969-Cadillac"]
})

# Append to List a 2nd Dictionary of key/values
InfoDb.append({
    "FirstName": "Sunny",
    "LastName": "Naidu",
    "DOB": "August 2",
    "Residence": "Temecula",
    "Email": "snaidu@powayusd.com",
    "Owns_Cars": ["4Runner"]
})

InfoDb.append({
  "FirstName": "Sarah",
    "LastName": "Liu",
    "DOB": "January 12",
    "Residence": "San Diego",
    "Email": "mail2sarahl@gmail.com",
    "Owns_Cars": ["2010 Lexus IS 250"]
})

def collect_data(): 

  print("Please enter your first name:")
fn = input()
print(fn)
print("Please enter your last name:")
ln = input()
print(ln)
print("Please enter your date of birth:")
dob = input()
print(dob)
print("Please enter your county:")
county = input()
print(county)
print("Please enter your favorite color:")
color = input()
print(color)
print("Please input your favorite movie:")
movie = input()
print(movie)
print("Please input your owned cars:")
Owns_Cars = input()
print(Owns_Cars)

# Append to List a Dictionary of key/values related to a person and cars
InfoDb.append({

  "FirstName": fn,
    "LastName": ln,
    "DOB": dob,
    "Residence": county,
    "Fav_Color": color,
    "Fav_movie": movie,
    "Owns_Cars": Owns_Cars
})

def more_info():
    while True:
        ans = input("Do you want to add more info to the database? ")
        if ans == "yes":
            name = True
            collect_data() #collect data if input is "yes"
            print()
        else: #stop function if input isn't "yes"
            break




# Print the data structure
print(InfoDb)
Amay 
Please enter your last name:
Advani
Please enter your date of birth:
june 10
Please enter your county:
San Diego
Please enter your favorite color:
Blue
Please input your favorite movie:
Harry potter
Please input your owned cars:
2012 prius
[{'FirstName': 'John', 'LastName': 'Mortensen', 'DOB': 'October 21', 'Residence': 'San Diego', 'Email': 'jmortensen@powayusd.com', 'Owns_Cars': ['2015-Fusion', '2011-Ranger', '2003-Excursion', '1997-F350', '1969-Cadillac']}, {'FirstName': 'Sunny', 'LastName': 'Naidu', 'DOB': 'August 2', 'Residence': 'Temecula', 'Email': 'snaidu@powayusd.com', 'Owns_Cars': ['4Runner']}, {'FirstName': 'Sarah', 'LastName': 'Liu', 'DOB': 'January 12', 'Residence': 'San Diego', 'Email': 'mail2sarahl@gmail.com', 'Owns_Cars': ['2010 Lexus IS 250']}, {'FirstName': 'Amay ', 'LastName': 'Advani', 'DOB': 'june 10', 'Residence': 'San Diego', 'Fav_Color': 'Blue', 'Fav_movie': 'Harry potter', 'Owns_Cars': '2012 prius'}]

For Loop through index

def print_data(d_rec):
    print(d_rec["FirstName"], d_rec["LastName"])  # using comma puts space between values
    print("\t", "Residence:", d_rec["Residence"]) # \t is a tab indent
    print("\t", "Birth Day:", d_rec["DOB"])
    print("\t", "Cars: ",d_rec["Owns_Cars"])  # end="" make sure no return occurs
   # print(", ".join(d_rec["Owns_Cars"]))  # join allows printing a string list with separator
    print()


# for loop iterates on length of InfoDb
def for_loop():
    print("For loop output\n")
    for record in InfoDb:
        print_data(record)

for_loop()
For loop output

John Mortensen
	 Residence: San Diego
	 Birth Day: October 21
	 Cars:  ['2015-Fusion', '2011-Ranger', '2003-Excursion', '1997-F350', '1969-Cadillac']

Sunny Naidu
	 Residence: Temecula
	 Birth Day: August 2
	 Cars:  ['4Runner']

Sarah Liu
	 Residence: San Diego
	 Birth Day: January 12
	 Cars:  ['2010 Lexus IS 250']

Amay Advani
	 Residence: San Diego
	 Birth Day: June 10
	 Cars:  2012 Prius

Quiz that Stores in list/dictionaries

questions = 6
correct = 0

def question_and_answer(prompt, answer):
    print("Question: " + prompt)
    inp = input()
    print("Answer: " + inp)
    
    if answer == inp.lower():
        print("Good Job! That is the right answer!")
        global correct
        correct += 1
    else:
        print ("That is Wrong!")
        
    return inp
 
Question1 = question_and_answer("Which country gifted the Statue of Liberty to the US? \t 1 for France \t 2 for England \t 3 for Germany \t 4 or Italy", "1")
Question2 = question_and_answer("What is the name of the longest river in South America? \t 1 for Mississippi River \t 2 for Amazon River", "2")
Question3 = question_and_answer("Which fictional city is the home of Batman? \t 1 for San Diego \t 2 for Central City \t 3 for Gotham City  ", "3")
Question4 = question_and_answer("How many feet are in a mile?", "5280")
Question5 = question_and_answer(" Who is the author of the Harry Potter series \t 1 for JK Rowling \t 2 for Rick Riordan \t 3 for William Shakespeare", "1")
Q6 = question_and_answer("What number is the iron in the periodic table of elements?", "26")

print(correct, "answers correct", correct*100/questions,"%")
    
Quiz = {
    "Question One": Question1 ,
    "Question Two": Question2 ,
    "Question Three ": Question3,
    "Question Four ": Question4,
    "Question Five": Question5,
    "Question Six": Q6
}

print("Your answers:",Quiz)
Question: Which country gifted the Statue of Liberty to the US? 	 1 for France 	 2 for England 	 3 for Germany 	 4 or Italy
Answer: 1
Good Job! That is the right answer!
Question: What is the name of the longest river in South America? 	 1 for Mississippi River 	 2 for Amazon River
Answer: 2
Good Job! That is the right answer!
Question: Which fictional city is the home of Batman? 	 1 for San Diego 	 2 for Central City 	 3 for Gotham City  
Answer: 3
Good Job! That is the right answer!
Question: How many feet are in a mile?
Answer: 5820
That is Wrong!
Question:  Who is the author of the Harry Potter series 	 1 for JK Rowling 	 2 for Rick Riordan 	 3 for William Shakespeare
Answer: 1
Good Job! That is the right answer!
Question: What number is the iron in the periodic table of elements?
Answer: 26
Good Job! That is the right answer!
5 answers correct 83.33333333333333 %
Your answers: {'Question One': '1', 'Question Two': '2', 'Question Three ': '3', 'Question Four ': '5820', 'Question Five': '1', 'Question Six': '26'}

Hacks

  • Add a couple of records to the InfoDb
  • Try to do a for loop with an index
  • Pair Share code somethings creative or unique, with loops and data. Hints...
    • Would it be possible to output data in a reverse order?
    • Are there other methods that can be performed on lists?
    • Could you create new or add to dictionary data set? Could you do it with input?
    • Make a quiz that stores in a List of Dictionaries.