4- Write a program by using function that asks the user for
entering a positive integer
number (a) and then calculate the factorial of the number. Draw the
Trace Table
(8 Marks)( k/2, T/2, C/2, A/2)
Enter a number: 4
Factorial (4) = 4! =4*3*2*1=24
use python pls
BECAUSE OF THE IDENTATION PROBLEM WHILE SUBMITTING THE CODE SO THAT IM ALSO GIVING YOU THE SCREENSHOT SO THAT YOU CAN REFER IT :
PYTHON CODE :
def factorial(n): # factorial function
if n == 1 : # if n is 1
return n
else:
return n * (n - 1) # recursive function
n = int(input("Enter the number: ")) # read the number
if n == 0 : # if n is zero
print("Factorial of 0 is : 1")
else:
print("Factorial of",n,"is :",factorial(n)) # print the result
INPUT & OUTPUT :
4- Write a program by using function that asks the user for entering a positive integer...
In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686
C++ Write a program that asks user for a positive integer side length. If they enter an illegal value, they must be prompted to enter a good one until they do. It then displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4, the program should display:
USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)
C++ coding answer 5. Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. Input Validation: Do not accept a negative starting number.
Write a program that asks the user to input a 4-digit integer and then prints the integer in reverse. Your program needs to implement a function reverse that will take in as input the 4-digit number and print it out in reverse. Your code will consist of two files: main.s and reverse.s. Main.s will ask for the user input number and call the function reverse. For ARM/Data Structure needs to be able to run on Pi Reverse.s will take in...
need this by tonight pls using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operator
C++ Write a program that asks user to input three positive integers one at a time, then compute and output the largest entered number. Use if-else statements for three integer comparison and use for loops for a user validation. Example output: Enter an integer: -7 Invalid! Number must be positive. Enter an integer: -2 Invalid! Number must be positive. Enter an integer: 5 Enter an integer: 7 Enter an integer: 1 Largest number: 7
Using loops, write a C# program that asks the user to enter repeatedly an integer number, it stops when the user enters -1, then the program should display how many numbers were entered, their the sum and their average
Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming
Use Python Write a program that asks the user to enter the expression of a function to a single variable x. From this expression, using the sympy library, do the following: Calculate the images for x ranging from 0 to 19