Question

12. What is the output of this program? Your answer: 1 def main(): 2 print(The numbers are:) 3 for i in range (2,25): 4 iso
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

In First Code It will show You Prime Numbers Between 2 to 25

def main(): // define function

print('enter the value') // print statement

for i in range(2,25): // loop which continue between this two number,where 2 is initial value and 25 is ending value.

isOne(i)

def isOne(number): // def function which take argument as number

isOne=true // value will assign to isOne

i=2 // assign value of i

while i < number and isOne : // when i is smaller then number and isOne function

if number % i == 0 // check if number modulo i and value will equals to zero

isOne = false // break the loop

i+=1 // increase the value of i with +1

if isOne == true: // if condition match then value will assign to isOne function

print ('\t',i) // print the value of i

Output Is Look Like This :

ISURE 1) def isone (number): isOne=True i=2 while i < number and isOne: if number % i == 0: isOne=False i+=1 if is One == Tru

2)

Here the value of i at first time will be 1 so first loop of i=1 then we will go to nested loop here the first value of j is j=6 and it will reduce to 0 through -1 sign.

then we comparaing that j is greater then or equal to i.

starting from first 6 is greater then 1 is true so we print 6,5,4.. and so on till 1 then 0 is not greater then 1 so it will go into else part.

Then we will go to main loop for i in range 6 now its value is increased by 1

This will continue till its all requirements are made fulfil.

Its Output is Shown below.

In [2]: for i in range (1, 6 + 1): for j in range (6, 0, -1): if j >= i: print(j, end= ) else: print( , end = ) print()

ISURE 1) def isone (number): isOne=True i=2 while i < number and isOne: if number % i == 0: isOne=False i+=1 if is One == True: print ("\t',i) main() The Numbers are: click to scroll output; double click to hide

In [2]: for i in range (1, 6 + 1): for j in range (6, 0, -1): if j >= i: print(j, end=' ') else: print(' ', end = '') print() 6 5 4 3 2 1 6 5 4 3 2 6 5 4 3 6 5 4

Add a comment
Know the answer?
Add Answer to:
12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers...
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
  • 5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x...

    5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x is ", xx) values=[8 ,2 , 6 , 6 ,2 ,6) c=0 for i in range (len (values)): if (values[i] == xx): C=C+1 if c> 0 : print ("Return ", c) return c else: C = 100 print ("Return ", c) return c A = Fungsi (2) print ("The A is ", A) B= Fungsi (6) + Fungsi (7) print ("The Bis", B)

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • Is the following program correct? If it is correct, what is the output? If it is...

    Is the following program correct? If it is correct, what is the output? If it is incorrect, please correct the code and write down the output of the program. def fac(n): i=0 sum=0 while i<=n: sum*=i return sum def main(): print(fac(5)) main() PYTHON PLEASE

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • I have to write a program where the program prints a deck of cards. instead of having your regula...

    I have to write a program where the program prints a deck of cards. instead of having your regular suits and numbers the program will use a value for a number, id will be either rock, paper, or scissors, and the coin will be heads or tails. print example: 2 of rock heads. If the user is enters 1 the program will print out 30 of the print example and arrange them by there values. if the user enters 2...

  • #Which function has the most parameters? def Menu(): print ("Your Name Main Menu") print("1. Sum") print("2....

    #Which function has the most parameters? def Menu(): print ("Your Name Main Menu") print("1. Sum") print("2. Product") print("3. information") print("4. Quit") def Sum(x): x= x* 2 y = 10 answer = x+y return x,y,answer def Product(w,z): answer = w*z print (answer) def Calc(a,b,c): return a*b*c Question options: Product Calc Menu Sum

  • Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number...

    Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number to search (until ^D) and display the position of the number in the sorted vector. Try your program for the following user input: 1 15 18 40 30 50 ^D The output should be: -1 2 -1 7 5 -1 int binary_search(vector<int> v, int from, int to, int value) { if (from > to) return -1; int mid = (from + to) / 2;...

  • Please help, Array does not print properly. I need to print out the 8 class numbers...

    Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial {    public static void main(String[] args) {    int newclass = 0;    int countclass = 0;    final int class_Max = 8;    int[] classarray =...

  • Python 3 Question: All I need is for someone to edit the program with comments that...

    Python 3 Question: All I need is for someone to edit the program with comments that explains what the program is doing (for the entire program) def main(): developerInfo() #i left this part out retail = Retail_Item() test = Cash_Register() test.data(retail.get_item_number(), retail.get_description(), retail.get_unit_in_inventory(), retail.get_price()) answer = 'n' while answer == 'n' or answer == 'N': test.Menu() print() print() Number = int(input("Enter the menu number of the item " "you would like to purchase: ")) if Number == 8: test.show_items() else:...

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