PYTHON:
Please trace the following programs:
Program 1
----------------
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration", iteration, "count is:", count)
iteration += 1
--------------------------------
Program 2
--------------------
count = 0
phrase = "hello, world"
for iteration in range(5):
index = 0
while index < len(phrase):
count += 1
index += 1
print("Iteration ", iteration, "count is:", count)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
PROGRAM 1
Iteration 0 count is: 12
Iteration 1 count is: 24
Iteration 2 count is: 36
Iteration 3 count is: 48
Iteration 4 count is: 60
PROGRAM 2
Iteration 0 count is: 12
Iteration 1 count is: 24
Iteration 2 count is: 36
Iteration 3 count is: 48
Iteration 4 count is: 60
Kindly revert for any queries
Thanks.
PYTHON: Please trace the following programs: Program 1 ---------------- iteration = 0 count = 0 while...
using python 1. Translate the following FOR loops to equivalent WHILE loops: a. for count in range(100): print(count) b. for count in range(1, 101): print(count) c. for count in range(100, 0, –1): print(count)
Task 4: for Loops (PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS #!/usr/bin/python3 # Measure some strings: words = ['cat', 'window', 'defenestrate'] for w in words: print(w, len(w)) #!/usr/bin/python3 # Measure some strings: words = ['cat', 'window', 'defenestrate'] for w in words: print(w, len(w)) forvar in list(range(5)): print (var) for letter in 'Python': # traversal of a string sequence print ('Current Letter :', letter) print() fruits = ['banana', 'apple', 'mango'] for fruit in fruits: # traversal of List...
Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...
Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...
Your Python program should perform the following three tasks: 1. After getting a word of input from the user (i.e., any string), your program should use a while (or for) loop to print out each of the letters of the word. Just remember that strings in Python start with element 0! 2. Your program should then use another loop to print out each of the letters of the (same) word in reverse order! 3. Ask the user for a letter...
trace
e following C++ program and provide the correct output: int x = 20, count=0; do { cout << x; x = 4* (x + 5)/5; count++; }while (count < 2);
Questin 1 (CO 2) Which of the following is not a valid name in python? last_name lastName last name lname Question 2 (CO 3) How many times will “Hello World” be displayed after the following code executes? num=2 while num<12: print("Hello world") num+=2 2 12 5 4 Question 3 (CO 1) The following code contains an error, what type of error is it and what line number is it? 1 count=1 2 while count<4 3 print("count = ",...
In Python Trace "Stars.py" by drawing a table that shows the values of relevant variables (row and star) and keeping track of the output. This program contains a nested for loop, so for each iteration of the outer loop, the inner loop executes in its entirety: row star 1 1 2 1 2 2 3 1 3 2 3 3 ... ... #******************************************************************** # stars.py # # Demonstrates the use of nested for loops. #******************************************************************** #----------------------------------------------------------------- # Prints a triangle...
Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...
Python 3
5. (16 points) Determine the big-O running time of each of the following functions: def pi (a) for i in range(len (a)): print (a[i]) for i in range(len(a)): print (ali]) def p2(a): for i in rangeClen(a)): for j in a: print (ati].j) def p3(a): for i in a: for j in a: print (i,j) def p4(a): for i in range(len(a)): pi(a) def p5(a): for i in range(len(a)): p3 (a) def p6(a): for i in range(len(a)): p5(a) def p7...