In: Computer Science
Create a variable named specChars and assign it the values of all the punctuation items available on the top row of the keyboard, starting with the value above the number 1 through the value above the number 0. For example: !@#........ Prompt the user to enter a number between 1 and 10. For the number of times given by the user, randomly select one of the punctuation items in the specChars variable using the random.choice() function. Print the value that is chosen.
If you have any doubts then please comment below.
import random
specChars={'!':ord('!'),'@':ord('@'),'#':ord('#'),'$':ord('$'),'%':ord('%'),'^':ord('^'),'&':ord('&'),'*':ord('*'),'(':ord('('),')':ord(')')}
Number=int(input("Enter number of times(1-10)"))
for i in range(Number):
sc=random.choice(list(specChars))
print("Randomly choosen special character is {0} and it's value is
{1}".format(sc,specChars[sc]))
Test Case 1:
Test Case 2:
Test Case 3:
Test Case 4: