Ed's lecture code from 9/24/2024
parent
8b80284979
commit
272bd4fc51
|
@ -158,5 +158,6 @@ cython_debug/
|
|||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# Program to calculate the perimeter of a rectangle.
|
||||
|
||||
|
||||
length = 4
|
||||
|
||||
width = 2
|
||||
|
||||
perimeter = (length + width) * 2
|
||||
|
||||
print("The perimeter of this rectangle is ",perimeter)
|
|
@ -0,0 +1,14 @@
|
|||
# Program to calculate the perimeter of a rectangle.
|
||||
|
||||
print("\nCalculate the perimeter of a rectangle\n")
|
||||
|
||||
|
||||
length = input("Enter a value for length ")
|
||||
length = float(length)
|
||||
|
||||
width = input("Enter a value for width ")
|
||||
width = float(width)
|
||||
|
||||
perimeter = (length + width) * 2
|
||||
|
||||
print("\nThe perimeter of these number is ",perimeter)
|
|
@ -0,0 +1,23 @@
|
|||
# Program to calculate the perimeter of a rectangle.
|
||||
# This version uses the triple quoted multiline string to create a message about
|
||||
# the purpose of the program.
|
||||
|
||||
message = '''
|
||||
\t\tProgram to calculate the perimeter of a rectangle
|
||||
|
||||
Enter all values to calculate the result.
|
||||
|
||||
'''
|
||||
|
||||
print(message)
|
||||
|
||||
|
||||
length = input("Enter a value for length ")
|
||||
length = float(length)
|
||||
|
||||
width = input("Enter a value for width ")
|
||||
width = float(width)
|
||||
|
||||
perimeter = (length + width) * 2
|
||||
|
||||
print("\nThe perimeter of these number is ",perimeter)
|
|
@ -0,0 +1,29 @@
|
|||
# Program to calculate the volume of a rectangular solid.
|
||||
# This is the Rectangle program extended to three dimensions.
|
||||
|
||||
#Consider the following:
|
||||
# Create new programs from existing running programs whenever possible.
|
||||
# Try to be as consistent in your style as possible.
|
||||
# If your company has existing programs try to copy the existing style whenever possible.
|
||||
|
||||
message = '''
|
||||
\t\tProgram to calculate the volume of a rectangular solid
|
||||
|
||||
Enter all values to calculate the result.
|
||||
|
||||
'''
|
||||
|
||||
print(message)
|
||||
|
||||
length = input("Enter a value for length ")
|
||||
length = float(length)
|
||||
|
||||
width = input("Enter a value for width ")
|
||||
width = float(width)
|
||||
|
||||
height = input("Enter a value for height ")
|
||||
height = float(height)
|
||||
|
||||
volume = length * width * height
|
||||
|
||||
print("\nThe volume of these number is ",volume)
|
|
@ -0,0 +1,8 @@
|
|||
# Extremely minimal addition program.
|
||||
|
||||
data1 = 4
|
||||
data2 = 2
|
||||
|
||||
sum = data1 + data2
|
||||
|
||||
print(sum)
|
|
@ -0,0 +1,11 @@
|
|||
# Read data values from the keyboard as strings then convert them to floats.
|
||||
|
||||
data1 = input("Enter a value for data1 ")
|
||||
data1 = float(data1)
|
||||
|
||||
data2 = input("Enter a value for data2 ")
|
||||
data2 = float(data2)
|
||||
|
||||
result = data1 + data2
|
||||
|
||||
print("The sum of these values is ",result)
|
Loading…
Reference in New Issue