top of page
Search

Module_5

  • Writer: Angela Porcelli
    Angela Porcelli
  • Feb 13, 2021
  • 2 min read

Updated: Feb 15, 2021

Part 1 directions "Write a Python program to execute a string containing Python code."


I wanted to write a functional code that could be used in people's daily life, so I decided to come up with a code to find an expected weekly gross income. This tool could be utilized while creating personal budgets or it could be used by a small business as a basic timesheet application.


The code asks the user to input the total hours they worked every day of the week. The code is written to recognize the user's input as an integer so that the addition operator can be utilized.

variable = int(input for i in range(6))


The code adds the first two inputs together and then adds the subsequent input to the previous sum.

S=(Mon + Tues)

T=(Wed+S)


After getting the total sum of all the inputs, the program will ask for the rate of the user's pay. Since most workers don't make an even amount per hour, the code was written to accommodate decimals.

P=float(input("Number?"))


Once the total sum has been computed and the user has inputted their rate of pay, the program will multiply the total sum by the rate of pay to calculate the user's gross weekly income.

B=(G*P)




Part 2 directions "Write a Python function to insert a string in the middle of a string".


I wanted a function that would be useful in my own life, so I decided to create a code that would be useful when creating foster agreements for shelter animals. This code would allow the foster manager to input the name of the animal to be fostered as well as the estimated foster duration, resulting in the string 'x will be fostered for y'.


First, I defined the function as insert_sting_middle with the argument elements consisting of string and word. Then I set the format of how I would like the string returned.

def insert_string_middle(str,word): return str[:2] + word + str[2:]


Next, I used the input function so that the user would be asked to input both the animal's name and then how long the animal is to be fostered.

print("Enter foster name") x=input() print(x) y=input('Enter length of time') print(y)


Lastly, I indicated how I wanted the final information to be printed. I wanted the entire string to be printed on a single line instead of three separate lines due to the return format of return str[:2] + word + str[2:]. My print code was print(insert_string_middle('',x),'will be fostered for',y )



 
 
 

Recent Posts

See All
Final_Project

Problem description: The goal of graduating with a college degree is to have the ability to choose an employer that will provide an...

 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2021 by LIS 5937 - Python for Data Science Professions. Proudly created with Wix.com

bottom of page