In: Computer Science
python
Write a program that prints your name 100 times to the screen.
Write a function that takes a string s and an integer n as parameters and prints the
string s a total of n times (once per line).
Write a for loop that prints all the integers from 3141 to 5926, skipping every other
one.
Write a for loop that prints every 5th integer from 5926 down to 3141.
Write a program (using a for loop) to print the following:
****** ***** **** *** ** *
*********** ********* ******* ***** *** *
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
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: