Files
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# File: Pease-hw3a.py
|
||||
# Author: PEASE, NICHOLAS
|
||||
# Date: 05 OCT 2022
|
||||
# Section: 1002-LAB
|
||||
# E-mail: nicholas.pease@maine.edu
|
||||
# Description:
|
||||
# Write a small program that will prompt the user to enter a number repeatedly
|
||||
# until they enter ‘end’. Your program should prompt the user for at least once. Users
|
||||
# might input either an integer or a float; you don’t need to differentiate. You may assume
|
||||
# that all input will be either a number or the word ‘end’. When ‘end’ is entered, you
|
||||
# should report out the largest number entered
|
||||
# Collaboration:
|
||||
# Bryce Roy
|
||||
|
||||
persistent = 0
|
||||
user_input=""
|
||||
while user_input != "stop" and user_input != "end":
|
||||
user_input = input("Enter a number (or `end` to end): ")
|
||||
if user_input != "stop" and user_input != "end":
|
||||
if float(user_input) > persistent:
|
||||
persistent = float(user_input)
|
||||
print("The largest number is",persistent,"!")
|
||||
@@ -0,0 +1,24 @@
|
||||
# File: Pease-hw3b.py
|
||||
# Author: PEASE, NICHOLAS
|
||||
# Date: 05 OCT 2022
|
||||
# Section: 1002-LAB
|
||||
# E-mail: nicholas.pease@maine.edu
|
||||
# Description:
|
||||
# Write a program that gets two integers from the user and then prints the
|
||||
# numbers from the first to the second (inclusive), one per line. If the year with that number
|
||||
# is a leap year, print a message saying so. The leap years are those years that are divisible
|
||||
# by 4 (except for those divisible by 100, but not 400). Use range () in your program.
|
||||
# Collaboration:
|
||||
# I collaborated with no one.
|
||||
|
||||
first_year = int(input("Please enter first year: "))
|
||||
second_year = int(input("Please enter second year: "))
|
||||
for i in range(first_year, second_year+1):
|
||||
if i % 4 == 0:
|
||||
if i % 400 != 0 and i % 100 == 0:
|
||||
result = ""
|
||||
else:
|
||||
result = str(i) + " is a leap year!"
|
||||
else:
|
||||
result = i
|
||||
print(result)
|
||||
@@ -0,0 +1,18 @@
|
||||
# File: Pease-hw3c.py
|
||||
# Author: PEASE, NICHOLAS
|
||||
# Date: 05 OCT 2022
|
||||
# Section: 1002-LAB
|
||||
# E-mail: nicholas.pease@maine.edu
|
||||
# Description:
|
||||
# Examine the contents of a list, using len() and range(). Given a list, print out
|
||||
# the element index and contents for each element. Your program should initialize the list
|
||||
# of your choice and then print out the contents in the format specified. At the end, claim
|
||||
# that the middle entry is your favorite (round down if the list is even).
|
||||
# Collaboration:
|
||||
# I collaborated with no one.
|
||||
|
||||
monsters = [ "Squirtle","Venonat","Eevee", "Cherim","Bronzong","Bergmite"]
|
||||
print("The monster list is:")
|
||||
for i in range(0,len(monsters)):
|
||||
print(str(i)+": "+monsters[i])
|
||||
print("My personal favorite is "+str(monsters[len(monsters)//2]))
|
||||
@@ -0,0 +1,22 @@
|
||||
# File: Pease-hw3d.py
|
||||
# Author: PEASE, NICHOLAS
|
||||
# Date: 05 OCT 2022
|
||||
# Section: 1002-LAB
|
||||
# E-mail: nicholas.pease@maine.edu
|
||||
# Description:
|
||||
# Write a small program that asks the user for two numbers (x, y). For each
|
||||
# number from 1 to x (inclusive), print the first y multiples of that number on the same line.
|
||||
# Keep repeating this action until the user inputs any negative number
|
||||
# Collaboration:
|
||||
# I collaborated with no one.
|
||||
|
||||
x=1;y=1
|
||||
while x > 0 and y > 0:
|
||||
y = int(input("Hello, what is your first number? "))
|
||||
x = int(input("Hello, what is your second number? "))
|
||||
for y_i in range(y):
|
||||
x_list = [0]*(x)
|
||||
for x_i in range(1,x+1):
|
||||
x_list[x_i-1] = x_i+(y_i*x)
|
||||
print(*x_list)
|
||||
print("Goodbye")
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# File: Pease-hw3d.py \n",
|
||||
"# Author: PEASE, NICHOLAS \n",
|
||||
"# Date: 05 OCT 2022\n",
|
||||
"# Section: 1002-LAB\n",
|
||||
"# E-mail: nicholas.pease@maine.edu \n",
|
||||
"# Description: \n",
|
||||
"# Write a small program that asks the user for two numbers (x, y). For each \n",
|
||||
"# number from 1 to x (inclusive), print the first y multiples of that number on the same line. \n",
|
||||
"# Keep repeating this action until the user inputs any negative number\n",
|
||||
"# Collaboration: \n",
|
||||
"# I collaborated with no one."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 82,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1 2 3 4\n",
|
||||
"5 6 7 8\n",
|
||||
"9 10 11 12\n",
|
||||
"1 2 3\n",
|
||||
"4 5 6\n",
|
||||
"7 8 9\n",
|
||||
"10 11 12\n",
|
||||
"Goodbye\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"x=1;y=1\n",
|
||||
"while x > 0 and y > 0:\n",
|
||||
" y = int(input(\"Hello, what is your first number? \"))\n",
|
||||
" x = int(input(\"Hello, what is your second number? \"))\n",
|
||||
" for y_i in range(y):\n",
|
||||
" x_list = [0]*(x)\n",
|
||||
" for x_i in range(1,x+1):\n",
|
||||
" x_list[x_i-1] = x_i+(y_i*x)\n",
|
||||
" print(*x_list)\n",
|
||||
"print(\"Goodbye\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.10.5 64-bit",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.5"
|
||||
},
|
||||
"orig_nbformat": 4,
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "369f2c481f4da34e4445cda3fffd2e751bd1c4d706f27375911949ba6bb62e1c"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user