Question

Write a function called mixNumberString that takes a number (num) If the number is divisible by...

Write a function called mixNumberString that takes a number (num)
If the number is divisible by 3, it should return a string with the letter ‘z’ repeated P times where P is the remainder of input parameter num divided by 3. I.e num%3.
If it is divisible by 5, it should return “Beep” repeated P times where P is the remainder of input parameter num divided by 5. I.e num%5.
If it is divisible by both 3 and 5, it should return 15.
Otherwise, it should return the same number.

Write a function for checking the speed of drivers. This function should have one parameter: speed.
If speed is less than 70, it should return 0.
Otherwise, for every 5km above the speed limit (70), it should give the driver one demerit point and print the total number of demerit points. For example, if the speed is 80, it should return: 2
If the driver gets more than 12 points, the function should return the speed.

Homework Answers

Answer #1

Code:

def mixNumberString(num):
final_='' #empty string to return the final value
if (num%3==0 and num%5==0): #if num is divisible by both 3 and 5 then add 15
final_=final_+'15'
elif num%3==0: #if number is divisible by 3
for i in range(0,num//3): #iterate loop from 0 to num//3 eg:18 then 0 to 6
final_=final_+"z" #concatenate z to final_
elif num%5==0: #if num divisible by 5
for i in range(0,num//5): #concatenate Beep to final_
final_=final_+"Beep"
else:
final_=final_+str(num); #else add original number
return final_ #finallyy return the string
num=int(input("Enter the n value : "))
print(mixNumberString(num))


Code 1 and output Screenshots:

Code 2:

def CheckSpeed(speed): #check speed function
res=0 #final_result=0
if speed<70: #if speed less than 70 make res=0
res=0
elif (speed>=70): #if speed greater than 70
demerit_points=(speed-70)//5 #remove 70 from speed and then divide by 5 because for every 5 kms above 70 speed
res=demerit_points #set demerit_points as result
if demerit_points>12: #if the demerit_points >12 set res=speed
res=speed
return res #finally return the speed

speed=int(input("Enter the speed : ")) #asking user to enter the speed
print(CheckSpeed(speed)) #calling CheckSpeed() function

Code 2 and Output Screenshots:

Note : in the question given p is nothing but num%3 but if we take like that num%3=0 so i have assumed it as num/3 times as p value.

Note : if you have any queries please post a comment thanks a lot..always available to help you

Know the answer?
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
Similar Questions
1.Implement a function which will -       + Accept a number, num, and a list, my_list...
1.Implement a function which will -       + Accept a number, num, and a list, my_list as arguments       + return True if num exists in my_list       + return False otherwise 2. Write Python code to implement the following function - def find_in_list(item, my_list):     """     Look for an item from my_list (of items.)     If the item is found, return the index position of the item;     otherwise, return -1.     """       #add your code here...
(In Python) Complete the isPrime() function to take an int and return True if it is...
(In Python) Complete the isPrime() function to take an int and return True if it is a prime number and False if it is not. Note: A prime number is not evenly divisible (meaning, the remainder is not 0) for all numbers smaller than itself (down to 2). For example, if num is 7, then you could test: if 7 remainder 6 is not 0, then if 7 remainder 5 is not 0, then if 7 remainder 4 is not...
Create a function called, convert. This function receives a string parameter called word which only contains...
Create a function called, convert. This function receives a string parameter called word which only contains digits (the string represents a positive number) and returns a list of numbers. This is how the function works: - This function calculates the number of times each digit has repeated in the input string and then generates a number based on that using the following formula and adds it to a list. For instance, if the digit x has been repeated n times,...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
Write a Python program using that takes a number as input and then prints if the...
Write a Python program using that takes a number as input and then prints if the number is even or odd. The program should use a function isEven that takes a number as a parameter and returns a logical value true if the number is even, false otherwise.
Write a function num_day that takes a number in the range of 1 through 7 as...
Write a function num_day that takes a number in the range of 1 through 7 as a parameter and returns a string representing the corresponding day of the week, where 1=Monday, 2 =Tuesday, 3= Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The function should return the string "Error" if the parameter is that is outside the range of 1 through 7. You may assume that the parameter will be only numbers. Save the...
Use C code please! Write the function definition for a function called FindQuo that takes one...
Use C code please! Write the function definition for a function called FindQuo that takes one argument of type double (arg1 ) and returns a double.  The purpose of the function is to calculate the quotient of arg1 divided by a double (num) that will be entered by the user. Inside the function declare ask and get a double value from the user called num Use a loop (while or do/while) to ensure that the user does not enter a 0.0....
Write a function that takes as its parameter two integer variables and an output stream varlable....
Write a function that takes as its parameter two integer variables and an output stream varlable. The two integers correspond to the numerator, and denominatorThe function should check if the denominator is zero, then it should print out the message "Otherwise , it should calculate and print the quotient and the remainder to a file. c++
C++ Write a function named timesOfLetter that reads an array and returns the number of times...
C++ Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase vowel and each uppercase vowel appear in it using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it using reference parameter. • Write a function named isChar() that determines the input is alphabetic or not during inputting. • Write a function...
Design and implement a function with no input parameter which reads a number from input (like...
Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a valid input, the program calculates...