Question

In: Computer Science

python Write a program that prints your name 100 times to the screen. Write a function...

python

  1. Write a program that prints your name 100 times to the screen.

  2. Write a function that takes a string s and an integer n as parameters and prints the

  3. string s a total of n times (once per line).

  4. Write a for loop that prints all the integers from 3141 to 5926, skipping every other

    one.

  5. Write a for loop that prints every 5th integer from 5926 down to 3141.

  6. Write a program (using a for loop) to print the following:

      ******
       *****
        ****
         ***
          **
           *
    
  7. program (using a for loop) to print the following:
  ***********
   *********
    *******
     *****
      ***
       *
  1. Write a function square that takes two parameters, a string s and an integer l and prints a square of size l using the string. For example, square(‘‘Q’’, 5) should produce the following output:

       QQQQQ
       QQQQQ
       QQQQQ
       QQQQQ
       QQQQQ
    

Solutions

Expert Solution

1) Program:

#Take user input
name = input("Enter your name: ");
#Run a loop from 1 to 100 (Here end range is exclusive hence 101)
for i in range(1,101):
print(name, end=" ");

Output:

2) Program:

def printFunc(userstr,n):
#Run a loop from 1 to n (Here end range is exclusive hence n+1)
for i in range(1,(n+1)):
print(userstr);
def main():
#Take user input
name = input("Enter your string: ");
times = int(input("How many times you want string to be displayed: "))
printFunc(name,times);
main();

Program screenshot for better indentation:

Output:

3) Program:

i = 3141
for i in range(3141,5927,2):
print(i,end=' ');

Program screenshot for indentation:

Output:

4) Program:

i = 5926
for i in range(5926,3142,-5):
print(i,end=' ');

Program screenshot

Output:

7) Program;

def square(ch,length):
for i in range(0,length):
for j in range(0,length):
print(ch,end=' ');
print();
def main():
userCh = input("Enter character: ");
l = int(input("Enter number: "));
square(userCh,l);
main();
  

Program screenshot

Output:


Related Solutions

Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
Write an assembly language program that prints your first name in the output. Use immediate addressing...
Write an assembly language program that prints your first name in the output. Use immediate addressing with a hexadecimal constant to designate the operand of CHARO for each letter of your name. Comment each line except STOP and END. Cut and paste the Assembler Listing into your document and paste a screen shot of the Output area of the Pep8. Use the name "Kevin" as example Assembler Listing Screen Shot of Output area of the Pep8 program
In Python write a program that calculates and prints out bills of the city water company....
In Python write a program that calculates and prints out bills of the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of r means residential use, a code of c means commercial use, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:Three types of customers and their billing rates: Code...
Python # Write a program that examines three variables—x, y, and z # and prints the...
Python # Write a program that examines three variables—x, y, and z # and prints the largest odd number among them. # If none of them are odd, it should print a message to that effect. n = input('Enter the 1st Integer x: ') x = int(n) n = input('Enter the 2nd Integer y: ') y = int(n) n = input('Enter the 3rd Integer z: ') z = int(n) if x % 2 == 0 and y % 2 ==...
Python Assume s is a string of numbers. Write a program that prints the longest substring...
Python Assume s is a string of numbers. Write a program that prints the longest substring of s in which the numbers occur in ascending order and compute the average of the numbers found. For example, if s = '561984235272145785310', then your program should print: Longest substring in numeric ascending order is: 14578 Average: 5 In the case of ties, print the first substring. For example, if s = '147279', then your program should print Longest substring in numeric ascending...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle. (NAME = John Doe) 2)Write a Program that intializes X to 10, Y to 20 and Z to -50, adds X and Y and Z and prints the following the value of each variable, for example value of x is 10 as well as the result of the addition.
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Python Write a program that takes a text filename as command line argument, and prints number...
Python Write a program that takes a text filename as command line argument, and prints number of times each letter occurred in this file.
In python write a program which prints the longest substring of numbers which occur in ascending...
In python write a program which prints the longest substring of numbers which occur in ascending order s=342153476757561235
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT