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

Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do...
Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do we appreciate!" (hint use a for loop). Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages. Write a java program that will ask the user to enter a number and print out to the screen until the number -3 is entered. Write a JAVA program that calls a method that finds...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out your name and PRINTS OUT any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one parameter, a number,...
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
Description Write a program that prints out your name, the course ID of this class, what...
Description Write a program that prints out your name, the course ID of this class, what programming/computer courses you've taken. Ask the user for two numbers. Show the sum of the two numbers, the difference, the product and the quotient. For the difference subtract the second number from the first, for the quotient, use the first number as the numerator(dividend) and the second as the denominator(divisor). Sample Output: My name is Jianan Liu, I'm in course CS36. I've taken: C...
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
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT