EMT 1111

Tip/Tax Calculator Code: In this section, we learned how to assign values to user made variables like “Total” and “Meal”. We also used the “input” command in order to allow the user to enter the desired meal value.

meal = float(input(“Enter Price.”))
tax = 0.0675
tip = 0.15

meal = meal + meal * tax
total = meal + meal * tip

print(“%.2f” % total)

 

 

Date and Time

We can keep track of what happens in Python using the datetime command.

If you want to display the current time we can use the function datetime.now() with a variable “now” and then use the “print(now)” command to retrieve it. If you only want a portion of the time and date information you can specify by using “print now.year”, “print now.month”, and print now.day”.

 


 

Age Program: Determines if you’re an infant, child, teenager, or adult by allowing the user to input a value and then matching the input with each of the “elif” conditions until the statement is True which will then prompt the program to display that “elif’s” statement print answer.

answer = float(input(“Please enter a your age.”))
if answer <= 1:
print (“You are an infant.”)
elif answer > 1 and answer < 13:
print (“You are a child.”)
elif answer >= 13 and answer < 20:
print (“You are a teenager.”)
elif answer >= 20:
print (“You are an adult.”)

Conditionals and Control Flow

Conditionals have 3 key commands which are “if”, “elif”, and “else”. Python goes through the “if” conditional first and tests for the input’s membership in it, if the result is False, Python will move on to the “elif” conditional and test membership again. You can have multiple “elif” statements, but you can also use the “else” conditional which is only “True” when all the previous conditions are “False”.

 

PygLatin

 

Turtle Homework: This code geneates a turtle that does random turns and advantces random distances by taking advantage of the random function in order to make our program randomly select a number between 0 and 100, randomly select an angle between as its direction of movement, and also select a random number of steps for the turtle to advance and right after that go back to its original position and repeat the cycle for a total of 100 times.

import turtle
import random

b = turtle.Screen()
b.bgcolor(“Red”)

James = turtle.Turtle()
James.color(“Black”)
James.pencolor(“White”)
James.pensize(2)

for x in range (0,100):
distance = random.randint(0,150)
James.right (random.randrange(0,45))
James.forward (distance)
James.backward (distance)

 

Functions

 

Taking a Vacation

This section was all about using Python as a vacation planner by setting functions and conditions like “if”, “elif”, and “else” to store each location’s expenses costs and then give the user a clear estimate of the whole trip’s cost. This program makes it easy for the user to add any other expenses they might need to make and know what the total value of the trip would become.

 

Lists and Dictionaries

A list is a data structure in Python that is a mutable, or changeable. Each element or value that is inside of a list is called an item. Like lists dictionaries can easily be changed. Dictionaries can be contained in lists and vice versa. Lists are ordered sets of objects, whereas dictionaries are unordered sets and they belong to the built-in mapping type.

 

A Day at the Supermarket

 

The student becomes Prof.

This section aims to teach us how to make a “gradebook” in Python with the use of Lists and Dictionaries.

 

Lists and Functions

In this section shows how to make use of a single list that contains multiple lists and how to use them in a function like .append() which adds an item to the list, n.pop(index) to remove the item at the index, and join_lists.

 

Battleship