Question

Using Python... Be sure to include the first line that makes the file an executable file...

Using Python...

Be sure to include the first line that makes the file an executable file in Linux.

File Name: PyramidBlocks.py

Python skills needed:

  1. Simple for loop (for var in range(num1,num2):
  2. Use of the range object
  3. Use of python math
  4. Creation of a Python Function
  5. Use of the print() method.

Code Assignment 1:

Alex sells pyramid wall art. In the design of his pyramids have each row has one more block than the last which means row 10 has 10 blocks, row 9 will have nine blocks .... Different customers want different size pyramids so Alex wants a simple function that when he enters the number of rows, it will return the number of blocks he needs for the pyramid.

Create the function PyramidBlocks(rows) that adds up all the numbers from 1 to rows. For example: if the input is 4 then your program should return 10 because 1 + 2 + 3 + 4 = 10. For the test cases, the parameter rows will be any number from 1 to 1000.

Sample Test Cases

Input:12
Output:78

Input:140
Output:9870

start with:
def PyramidBlocks(rows):
    # python function code here

# ask for a number
needed = input("How many rows of blocks?\n")
# function call to test
print("Bocks Needed ", PyramidBlocks(needed))

Code Assignment 2:

Python skills needed:

  1. For loop (for var in range(num1,num2):
  2. Use of the range object
  3. Use of python math
  4. Creation of a Python Function
  5. Use of the print() method(s).
  6. Analytical skills

Ariana is looking to purchase an auto. She is thinking of getting a truck but is concerned about the gas mileage so you've offered to help her out.

Create the function MpgCostDiff in python that takes the MPG value, a float value, and the price of gas, a float value.

The function will display the cost of driving the 10,000 miles based on the MPG and price of gas.

It will also display the $ amount saved for each additional mpg increase for the next 20 values and display them in a column format like the following example:

This chart is based on the price of gas being $2.459 per gallon. You will need the following formula for calculating the cost to go 10,000 miles: 10000/mpg*price to calculate the cost savings, it will be the base cost minus the cost of the higher mpg.  

Base MPG 15 Cost per 10,000 miles $1,639.33

MPG 1 MPG 2 Savings
15 16 102.46
15 17 192.86
...... 18 more ...

def MpgCostDiff(mpg, gasPrice):
# python function code here

print(....)

# ask for a mpg
mpgIn = input("How many Miles per Gallon?\n")
# ask for a gas price
priceIn = input("What's the price of gas?\n")
# function call to test
MpgCostDiff(mpgIn, priceIn)

For Example: If I get a car that gets 10 mpg and gas is 2.50 per gallon, it will cost 10000/10*2.5 or $2,500.00 to drive 10,000 mi.es. If i get 11 mpg, it will cost: 10000/11*2.50 = $2,272.72. The cost savings is $2,500 - 2,272.72 or $227.27.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Assignment 1

while True:

try:

noRows = int(input('Number of Rows: '))

if noRows < 1 or noRows > 1000:

raise ValueError #this will send it to the print message and back to the input option

else :

count=0

i=0

while i<=noRows:

count=count+i

i+=1

print(count)

except ValueError:

print("Invalid integer. The number must be in the range of 1-10.")

Add a comment
Know the answer?
Add Answer to:
Using Python... Be sure to include the first line that makes the file an executable file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 2.7.14 Programming Assignment Shape Drawing With Notepad++(PLEASE READ AND FOLLOW THESE INSTRUCTIONS THOROUGLY AS THIS...

    Python 2.7.14 Programming Assignment Shape Drawing With Notepad++(PLEASE READ AND FOLLOW THESE INSTRUCTIONS THOROUGLY AS THIS ASSIGNMENT IS FOR PYTHON 2.7.14. ONLY AND I REALLY NEED THIS TO WORK!!! ALSO PLEASE HAVE THE CODE PROPERLY INDENTED, WITH WHATEVER VARIABLES DEFINED, WHATEVER IT TAKES TO WORK FOR PYTHON 2.7.14. I feel like nothing I do is working and I'm trying everything I can think of. ): In this assignment, the student will create a Python script that implements a series of...

  • For this lab, you will work with two-dimensional lists in Python. Do the following: Write a...

    For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...

  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • Hi. Please help me solve this in python using only while loops, if statements. Can't use...

    Hi. Please help me solve this in python using only while loops, if statements. Can't use for loops and lists. In this programming assignment, you will be writing a program that prints out several shapes via text. In this PA, you will be required to use functions and parameters. This is both to reduce redundancy and to make your code clean and well-structured. Name your program shaper.py Your program should have the capability to print out three different shapes: An...

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this...

    23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same as what you had for your chapter 13 labs). The following is an example of...

  • using this code to complete. it python 3.#Display Program Purpose print("The program will show how much...

    using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...

  • Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from...

    Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from number #1 link provided for the Data: -----> https://docs.google.com/spreadsheets/d/1TqhyxFKQlOHAyXpQBL-4C96kgZFBoMwUgE8-b33CqPQ/edit?usp=sharing PROBLEMS # 0.0 Import the libraries (pandas, matplotlib, and seaborn) Include the code line: %matplotlib inline #Include the code line: plt.style.use(“ggplot”) #Load the data using pandas #Inspect the data using head(), dtypes ANSWERD: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns plt.style.use('ggplot') %matplotlib inline df = pd.read_csv() print(df.head()) print(df.dtypes) # 1...

  • Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to...

    Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to the script (see below) 2. Read the file one line at a time (i.e., for line in file--each line will be a separate email address) 3. Print (to the screen) a line that "interprets" the email address as described below 4. When finished, display the total number of email addresses and a count unique domain names Each email address will either be in the...

  • My Python file will not work below and I am not sure why, please help me...

    My Python file will not work below and I am not sure why, please help me debug! ********************************* Instructions for program: You’ll use these functions to put together a program that does the following: Gives the user sentences to type, until they type DONE and then the test is over. Counts the number of seconds from when the user begins to when the test is over. Counts and reports: The total number of words the user typed, and how many...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT