Question

PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

PYTHON

4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function.
5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt").
6. Ask the user for 5 numbers. Save these as items in a list. Use a repetition structure to save the highest and lowest of these numbers as two variables, and only loop through the list one time.

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

Python code :

# a function that takes two arguments: a string called strText and a number called intNumber.
#This function will use a repetition structure (a While or For loop) to print strText intNumber of times.
def printingSTring(strText:str , intNumber:int):
for i in range(0,intNumber): #for loop for intNumber times tp print str
print(strText);
  
  
# Get an input from the user that is a file name with an extension
# (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt").
def fileExtention(inputStr:str):
if "." in inputStr: # if given inputstr containe . or not checking
extention = inputStr.split(".")[1] # if its extention with . then split and taking the extenstion
print(extention) #printing the extenstion
  
# Ask the user for 5 numbers. Save these as items in a list.
#Use a repetition structure to save the highest and lowest of these numbers as two variables, and only loop through the list one time.
def highestAndLowest():
numberList = [] #declaring list variable
print("enter the 5 numbers")
for i in range(0,5): #for loop for 5 times to enter number as the user
n = input()
numberList.append(n) #appending to list variable
  
highest = max(numberList) # storing the highest number ing given list
lowest = min(numberList) # storing the lowest number ing given list
print("Highest in the list is : ")
print(highest) #printing highest number
print("Lowest in the list is : ")
print(lowest) #printing lowest number
  
# function calling
printingSTring("hi",4)
fileExtention("myfile.ipynb")
fileExtention("myfile.txt")
highestAndLowest()

output:

hi                                                                                                                                                                                   

hi                                                                                                                                                                                   

hi                                                                                                                                                                                   

hi           

                                                                                                                                                                        

ipynb                                                                                                                                                                                

txt                

                                                                                                                                                                  

enter the 5 numbers                                                                                                                                                                  

2                                                                                                                                                                                    

5                                                                                                                                                                                    

9                                                                                                                                                                                    

3                                                                                                                                                                                    

5                                                                                                                                                                                    

Highest in the list is :                                                                                                                                                             

9                                                                                                                                                                                    

Lowest in the list is :                                                                                                                                                              

2

Note:

  • # indicates comment for code line
  • If any changes or update just do comment i will do
Add a comment
Know the answer?
Add Answer to:
PYTHON 4. Define a function that takes two arguments: a string called strText and a number...
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
  • In python Write a function called removeExtensión that is given the name of a file as...

    In python Write a function called removeExtensión that is given the name of a file as a string and returns the same string without the extension (the last "" and any following characters); if the given string has no extension, return the given string without changing it. For example, removeExtension"Chapter 3.9.txt") should return "Chapter 3.9" while removeExtension("Hello") should return "Hello"

  • IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a...

    IN PYTHON: Write a function that takes, as arguments, two lists, one of which is a character list and the other is the corresponding frequencies, and sorts the characters in ascending order of frequencies. The function should return a list consististing of two lists: the first list is the list of characters and the second is the list of corresponding frequencies, consistent with the rearranged characters. Name this function sortCharacters(characterList, frequencyList). For example, >>>sortCharacters(["a", "b", "c", "d"], [5, 8, 3,...

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • python In a program, write a function that accepts two arguments: a list, and a number...

    python In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • Using python, Write a function max3 that takes three numbers as its arguments and returns the...

    Using python, Write a function max3 that takes three numbers as its arguments and returns the greatest of these three numbers. Your submitted file for this problem should include (a) function definition, obviously, and (b) the code that calls that function (for this problem you do not have to package that calling code into the main() function although you may if you want to), so that if I run your *.py file it computes and prints something (e.g. few test...

  • Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers,...

    Please Use Python and provide explanations!!!! 1. Write a function called multiply_and_print that takes two numbers, multiplies them together, and prints out the sentence '____ times ____ is ____'. Ask the user for two numbers, and call multiply_and_print with their two numbers as arguments. 2.Write a function called roll_dice that rolls two six-sided dice and prints out the result of each die. Call it three times. (Remember, you can import the random module with the statement import random, and then...

  • in python Write a function, named max_of_two, that takes two numbers as arguments and returns the...

    in python Write a function, named max_of_two, that takes two numbers as arguments and returns the largest of the two values. (Note, this function is actually already provided in Python as max. Do not use the provided function; reason through the logic yourself).

  • Python Write a function that takes in two numbers as parameters. The function will then return...

    Python Write a function that takes in two numbers as parameters. The function will then return the value of the first parameters squared by the second parameter. Print the value of the return statement. Take a screenshot of both your code and your properly executed code after you have run it. Submit the screenshots here along with your .txt file.

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

    Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...

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
ADVERTISEMENT