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

  • Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method...

    Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method in the code file shared with you and test it in the main to get the element at index 3 of mylist2 . class Node: def __init__(self, e): self.element = e self.next = None class LinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def addFirst(self, e): newNode = Node(e) newNode.next = self.head self.head = newNode self.size = self.size + 1...

  • 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:...

  • My module page is correct but I don't believe I am using the main() function properly....

    My module page is correct but I don't believe I am using the main() function properly. One of my .py files is supposed to contain my definitions, which is the module file. My second .py file is supposed to properly call a main function that does what my program asks it to: First name, last name, age, and respond based off of input. For some reason I am struggling with using the main() function so that my program works. Any...

  • (Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers...

    (Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). The numbers are displayed in the order of their input and separated by exactly one space. (Hint: Read a number and store it to an array if it is new. If the number is already in the array, discard it. After the input, the array contains the distinct numbers.) Sample Run Enter...

  • #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

  • 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...

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