Write a function in this file called nine_lines that uses the function three_lines (provided below) to print a total of nine lines.
Now add a function named clear_screen that uses a combination of the functions nine_lines, three_lines, and new_line (provided below) to print a total of twenty-five lines. The last line of your program should call first nine_lines and then the clear_screen function.
The function three_lines and new_line are defined below so that you can see nested function calls. Also, to make counting “blank” lines visually easier, the print command inside new_line will print a dot at the
Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the parameter.
Example 2: Call your function from Example 1 three times with different kinds of arguments: a value, a variable, and an expression. Identify which kind of argument is which.
Example 3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.
Example 4: Create a function that takes an argument. Give the function parameter a unique name. Show what happens when you try to use that parameter name outside the function. Explain the results.
Example 5: Show what happens when a variable defined outside a function has the same name as a local variable inside a function. Explain what happens to the value of each variable as the program runs.
184 words
PermalinkReply
4
Write your own function that illustrates a feature that you learned in this unit. The function must take at least one argument. The function should be your own creation
Write a program that will perform the following:
A. Display Employee List
(Retrieve records from empList.txt, store it in a dictionary, display the employee list arranged by keys)
Note: Refer to example code in dictionary module (bbl) for sorting
B. Add Employee
(
Ask user to input the following data:
- unique employee number
- lastname
- firstname
- department
- rate per day
Write the employee record to the empList.txt
)
C. Add Payroll Record
(Ask user to input the following data:
-employee number
-month
-no of days worked
write the payroll record into the empMR.txt
)
D. Generate pay slip
Ask for employee number and month of the payslip to be generated
Create a payslip like statement written in a text file.
=============================================================
Payslip for the Month of _________________
Employee No.: ______________ Employee Name: _____________
Department: ________________
Rate per Day:_______________ No. of Days Worked: ________
Gross Pay: _________________
The volume of a sphere is 4/3πr3, where π has the value of "pi" given in Section 2.1 of your textbook. Write a function called print_volume (r) that takes an argument for the radius of the sphere, and prints the volume of the sphere.
Call your print_volume function three times with different values for radius.
Include all of the following in your Learning Journal:
The inputs and outputs to three calls of your print_volume.
matrix rotation
You are given two strings of same length and comprosied of + and - , print a new string that shows the result of the interaction of the two strings assume the following rules.
Interaction between two positive characters results in a positive character.
( "+" Against a "+" returns another "+")
Interaction between two negative characters results in a negative character.
("-" Against a "-" returns another "-")
Interaction between a positive and a negative character results in a " 0" (Neutral)
("+" against a "-" returns a "0")
Input: ++++++ ------
Output: 000000
Input: +-----+++- --+-+-++--
Output: 0-0-0-++0-
Assignment
Using the IDLE development environment, create a Python script named tryme4.py. (Note: an alternative to IDLE is to use a free account on the pythonanywhere website: https://www.pythonanywhere.com/)
Write a function in this file called nine_lines that uses the function three_lines (provided below) to print a total of nine lines.
Now add a function named clear_screen that uses a combination of the functions nine_lines, three_lines, and new_line (provided below) to print a total of twenty-five lines. The last line of your program should call first nine_lines and then the clear_screen function.
The function three_lines and new_line are defined below so that you can see nested function calls. Also, to make counting “blank” lines visually easier, the print command inside new_line will print a dot at the beginning of the line:
def new_line():
print('.')
def three_lines():
new_line()
new_line()
new_line()
Given two strings N and K. Your goal is to determine the smallest substring of N that contains all the characters in K. If no substring is present in N print no matches found.
Note: If character is repeated multiple times in K, your substring should also contain that character repeated same number of times.
Input: first line contains two strings N and K
Output: string representing the smallest substring as mentioned above
Input1: stealen lent
Output 1: tealen
Input 2: tomato tomatho
Output 2: No matches found
Write a program to find the sum of odd numbers in first N natural numbers.