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)
1.
num=int(input('Enter the number upto which the print numbers will be printed: ')) for n in range(2,num+1): primeNumber = True for i in range(2,n): if (n%i==0): primeNumber = False if primeNumber: print(n)
Output:
2.
import time start_time = time.time() for n in range(2,101): primeNumber = True for i in range(2,n): if (n%i==0): primeNumber = False if primeNumber: print(n) end_time=time.time() print('The total time spend for printing 100 prime numbers is ') print(end_time-start_time)
Output:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
The total time spend for printing 100 prime numbers is
0.0010023117065429688
USING PYTHON 1. Write a small program that asks for an integer number from the user...
Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
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
python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0 while cnt != 5: print(cnt) cnt = cnt + 2
Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...
Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...
Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...
Write a Python program that asks users to input an integer number and print the summation of its digits and total number of its digits. (i.e., for n=35, sum is 3+5=8, and total number of digits is 2).
Write a C program that asks the user to think of an integer number from 1 to 20. Have the computer guess what the number is by using a binary tree to determine the next guess. You can create the binary tree “by hand” by typing in a set of malloc commands and explicitly linking the nodes. (make the tree completely, then traverse the tree) Use a menu to provide the user with a selection to answer the results of...
Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...
Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...