Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lab 01 - Calculator/lab_01_part_a.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#
# 1.1 Part A
Fahrenheit= int(input("Enter temperature in Fahrenheit: "))
Celsius= ((Fahrenheit-32)*(5/9))
print("The temperature in Celsius:", Celsius)
8 changes: 7 additions & 1 deletion Lab 01 - Calculator/lab_01_part_b.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#
# 1.2 Part B
print("Area of a trapezoid")
height= int(input("Enter the height of the trapezoid: "))
lengthBottom= int(input("Enter the length of the bottom base: "))
lengthTop= int(input("Enter the length of the top base: "))
area= ((1/2)*(lengthBottom+lengthTop)*height)
print("The area is:",area)
6 changes: 5 additions & 1 deletion Lab 01 - Calculator/lab_01_part_c.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#
# 1.3 Part C
print('For the volume of a sphere.')
radius= int(input('Enter the radius: '))
volume= ((4/3)*(3.14*(radius**3)))
print('The volume is about', volume, '.')
54 changes: 53 additions & 1 deletion Lab 03 - Create a Quiz/main_program.py
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
#
print("Time for a Quiz!")
print("")
total= 0

question_one = int(input("1. What is my favorite number? "))
if question_one == 8:
total= total+1
print("Correct!")
else:
print("Incorrect.")
print("")

question_two = input("2. What did Jack break when he fell down? ")
if question_two == "his crown":
print("Correct!")
total= total+1
else:
print("Incorrect.")
print("")
print("3. What do your eyes do?")
answer_one= "1. smell"
answer_two= "2. see"
answer_three= "3. hear"
print(answer_one)
print(answer_two)
print(answer_three)
question_three= input("? ")
if question_three == "see":
print("Correct!")
total= total+1
else:
print("Incorrect!")
print("")

question_four= input("4. Is this the fourth question? ")
if question_four == "yes":
print("Correct!")
total= total+1
else:
print("Incorrect.")
print("")

question_five= input("What is the radius of the sun in miles? ")
if question_five== "432,288":
print("Correct!")
total= total+1
else:
print("Incorrect.")
print("")

print("Wow! You got", total, "questions right!")
print("That means your total score is", (100*(total/5)),"percent!")
print("")
99 changes: 98 additions & 1 deletion Lab 04 - Camel/main_program.py
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
#
# Completed Lab 4
import random
print("Welcome to Camel!")
print("You have stolen a camel to make your way across the great Mobi desert.")
print("The natives want their camel back and are chasing you down! Survive your desert trek and out run the natives.")
print("Hint: all capitals.")
print()

A = "A. Drink from your canteen."
B = "B. Ahead moderate speed."
C = "C. Ahead full speed."
D = "D. Stop for the night."
E = "E. Status check."
Q = "Q. Quit."
done = False
miles_traveled = 0
thirst = 0
camel_tiredness = 0
natives_distance = -20
canteen_drinks = 5

while not done:
print(A)
print(B)
print(C)
print(D)
print(E)
print(Q)
user_choice= input("Your choice: ")
if user_choice == "Q":
done=True

elif user_choice == "E":
print()
print("Miles traveled:", miles_traveled)
print("Drinks in canteen:", canteen_drinks)
print("The natives are", natives_distance, "miles behind you.")
print()
elif user_choice == "D":
camel_tiredness= 0
natives_distance+= random.randrange(7,14)
print()
print("Your camel is fully rested.")
print()
elif user_choice == "C":
miles_traveled+= random.randrange(10,21)
thirst= thirst+1
camel_tiredness+= random.randrange(1,4)
natives_distance+= random.randrange(7,14)
oasis= random.randrange(1,21)
print()
print("Your miles traveled are:", miles_traveled)
print()
elif user_choice == "B":
miles_traveled+= random.randrange(5,12)
thirst+= 1
camel_tiredness+= 1
natives_distance+= random.randrange(7,14)
print()
print("Your miles traveled are:", miles_traveled)
print()
elif user_choice == "A":
thirst= 0
canteen_drinks-= 1
print()
print("Your thrist is:", thirst)
print()

if oasis == 20:
camel_tiredness= 0
thirst= 0
canteen += 3
print("You found an oasis! You are no longer thirsty, you filled your canteen and your camel has rested.")
if miles_traveled >= 200 and not done:
print("You've won the game!")
done= True
if thirst > 4 and thirst <= 6 and not done:
print("You are thirsty!")
print()
if thirst > 6:
print("You died of thirst.")
print("You lose.")
print()
done=True
if camel_tiredness > 5 and camel_tiredness <= 8 and not done:
print("Your camel is getting tired.")
print()
if camel_tiredness > 8:
print("Your camel is dead.")
print("You lose.")
done= True
if natives_distance >= miles_traveled:
print("The natives have caught up to you.")
print("You lose.")
done= True
if natives_distance > miles_traveled+15:
print("The natives are getting close!")
print()
8 changes: 7 additions & 1 deletion Lab 06 - Loopy Lab/part_1.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@

# Lab 1 chapter 6
x = 10
for i in range(9):
for number in range(i+1):
print(x, end=" ")
x+= 1
print()
14 changes: 13 additions & 1 deletion Lab 06 - Loopy Lab/part_2.py
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
#
#Chapter 6 Lab 2
number = int(input("Number = "))
letter = "o"
spaces = " " * ((number * 2) - 3)
for row in range(number):
print(letter*2, end="")
print()
for row in range(number-2):
print(letter, spaces, end="")
print(letter)
for row in range(number):
print(letter*2, end="")
print()
43 changes: 42 additions & 1 deletion Lab 07 - Adventure/main_program.py
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
#
#!/usr/bin/env
#Lab 7: Adventure
#Evie Nelson
#11/20/17
''' An adventure game where the user can move through different rooms using north, east, south, and west. '''
#First, sketch the layout of the dungeon
#All of the rooms:
roomZero = ["You are in the main hall. There is a room to the north, to the east, and to the west.", 3, 2, None, 1]
roomOne = ["You are in the ballroom. There is a room to the east.", None, 0, None, None]
roomTwo = ["You are in the study. There is a room to the north and to the west.", 4, None, None, 0]
roomThree = ["You are in the west hall. There is a room to the east, to the south , and to the west.", None, 4, 0, 7]
roomFour = ["You are in the east hall. There is a room to the north, to the east, to the south, and to the west.", 6, 5, 2, 3]
roomFive = ["You are in the weapon room. There is a room to the west.", None, None, None, 4]
roomSix = ["You are in the meeting room. There is a room to the south.", None, None, 4, None]
roomSeven = ["You are in the bedroom. There is a large tapestry to the north and a room to the east.", 8, 3, None, None]
roomEight = ["You are in the secret room. There is a room to the south.", None, None, 7, None]
roomList = [roomZero, roomOne, roomTwo, roomThree, roomFour, roomFive, roomSix, roomSeven, roomEight]
currentRoom= 0
#print(roomList)
currentRoom= 0
done = False
while done != True:
print()
print(roomList[currentRoom][0])
userInput = input("What direction? ")
#directions
if userInput.lower()[0] == "n":
nextRoom = roomList[currentRoom][1]
elif userInput.lower()[0] == "e":
nextRoom = roomList[currentRoom][2]
elif userInput.lower()[0] == "s":
nextRoom = roomList[currentRoom][3]
elif userInput.lower()[0] == "w":
nextRoom = roomList[currentRoom][4]
elif userInput.lower()[0] == "q":
break
#if there isn't a room
if nextRoom == None:
print()
print("You can't go that way.")
else:
currentRoom = nextRoom
36 changes: 27 additions & 9 deletions Worksheets/worksheet_01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
and punctuation. Please limit the length of each line to 80 characters.

1. Write a line of code that will print your name.

print('Evie Nelson')
2. How do you enter a comment in a program?

#comment
3. What do the following lines of code output?
ALSO: Why do they give a different answer?

print(2 / 3)
print(2 // 3)
print(2 / 3) outputs 0.66666666
print(2 // 3) outputs 0
They output different answers since they are different equations.

4. Write a line of code that creates a variable called pi and sets
it to an appropriate value.

pi= 3.14
5. Why does this code not work?

A = 22
print(a)
The varaible is a capital a, so the print should be print(A).

6. All of the variable names below can be used. But which ONE of these is
the better variable name to use?
Expand All @@ -33,6 +35,7 @@
area
area_of_rectangle
Area_Of_Rectangle
The last one, Area_Of_Rectangle, is the best to use since it is the most specific.

7. Which of these variables names are not allowed in Python? (More than one
might be wrong. Also, this question is not asking about improper names, just
Expand Down Expand Up @@ -60,15 +63,18 @@
x2x
total%
#left
The variables #left, account number, account.number, great.big.variable, 2x, 1Apple, total%, and account# are not valid variable names in python.

8. Why does this code not work?

print(a)
a = 45
The variable a needs to be before the print line.

9. Explain the mistake in this code:

pi = float(3.14)
There is no print function.

10. This program runs, but the code still could be better. Explain what is
wrong with the code.
Expand All @@ -78,68 +84,80 @@
pi = x
area = pi * radius ** 2
print(area)
The varaible pi could be set to 3.14 instead of x.

11. Explain the mistake in the following code:

x = 4
y = 5
a = ((x) * (y))
print(a)
The a = ((x) * (y)) could be changed to a = (x*y).

12. Explain the mistake in the following code:

x = 4
y = 5
a = 3(x + y)
print(a)
The a = 3(x + y) should be a = (3*(x+y)).

13. Explain the mistake in the following code:

radius = input(float("Enter the radius:"))
It should be radius = float(input("Enter the radius:")).

14. Do all these print the same value? Which one is better to use and why?

print(2/3+4)
print(2 / 3 + 4)
print( 2 / 3+ 4 )
They all work but the first one is best to use since it is the easiest to read and understand.

15. What is a constant?
A variable that is set to one value and therefore is always that value.

16. How are variable names for constants different than other variable names?
They never change.

17. What is a single quote and what is a double quote?
Give and label an example of both.
A single quote is ' and a double quote is " .

18. Write a Python program that will use escape codes to print a double-quote
and a new line using the Window's standard. (Note: I'm asking for the Window's
standard here. Look it up out of Chapter 1.)

19. Can a Python program print text to the screen using single quotes instead
of double quotes?
Yes.

20. Why does this code not calculate the average?

print(3 + 4 + 5 / 3)

The 3, 4, and 5 added together need to be in () so they will be added together before being didveded by 3.

21. What is an ``operator'' in Python?
The symbols that allow math equations to be done in python. Such as <, >, +, -, *, **, and /.

22. What does the following program print out?

x = 3
x + 1
print(x)

It will print out 3.

23. Correct the following code:

user_name = input("Enter your name: )"

The correct code would be user_name = input("Enter your name: ")

24. Correct the following code:

value = int(input(print("Enter your age")))

The code needs to be:
value = int(input("Enter your age"))
print(value)



Loading