import random
print("Assignement 1 - Q1")
letter = input("Please enter a letter: ")
num = random.randrange(1,10)
print ("Random number is:",num)
print(letter * num)
print("Letter",letter,"Printed",num,"times!")
Assignement 1 - Q1 Please enter a letter: M Random number is: 8 MMMMMMMM Letter M Printed 8 times!
import random
print("Assignment 1 - Q2")
count = 0
for i in range(10000):
die1 = random.randint(1,6)
die2 = random.randint(1,6)
die3 = random.randint(1,6)
die4 = random.randint(1,6)
die5 = random.randint(1,6)
dice = [die1, die2, die3, die4, die5]
if dice.count(dice[0]) == 5:
count += 1
percentage = (count/10000) * 100
print("The percentage of Yahtzees is:", percentage, "%")
Assignment 1 - Q2 The percentage of Yahtzees is: 0.08 %
import random
print("Assignment 1 - Q3")
sentence = input("Enter any sentence: ")
no_spaces = sentence.replace(" ", "")
uppercase = no_spaces.upper()
print(uppercase)
Assignment 1 - Q3 Enter any sentence: Hi my name is maruthi HIMYNAMEISMARUTHI
print("Assignment 1 - Q4")
user_string = input("Please enter any string: ")
string_length = len(user_string)
print("The str len is:",string_length)
if string_length >= 5:
new_string = user_string[:5] + "***"
else:
new_string = user_string + "!"*(5-string_length)
print(new_string)
Assignment 1 - Q4 Please enter any string: hi sir how are you The str len is: 18 hi si***
print("Assignment 1 - Q5")
user_input = input("Enter a string of multiple words: ")
words = user_input.split()
for word in words:
print(word[0], end="")
Assignment 1 - Q5 Enter a string of multiple words: python is my favorite language pimfl