Question

In: Computer Science

Create a variable named specChars and assign it the values of all the punctuation items available...

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.

Solutions

Expert Solution

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:


Related Solutions

Create your own data type using a C++ structure. Assign values to a variable of that...
Create your own data type using a C++ structure. Assign values to a variable of that data type. Retrieve values from the variable of that data type. Description: In this lab you will choose the statements to create a program that: Creates a brand new data type called "Monster". Once created, creates a variable of type Monster and assign values to the variable and then display the contents. This lab will again take the form of a guided multiple-choice quiz...
10. We are trying to assign the value of a variable named “FirstNumber” to a variable...
10. We are trying to assign the value of a variable named “FirstNumber” to a variable named “SecondNumber”. They are declared as shown below. Which of the following statements is correct? double FirstNumber = 25.5; int SecondNumber; Group of answer choices c. SecondNumber = int.Parse (FirstNumber); b. SecondNumber = (double) FirstNumber; d. SecondNumber = double.Parse (FirstNumber); a. SecondNumber = (int)FirstNumber;
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable...
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use this pointer variable to initialize the myNums array from 2 to 200 and then display the array elements. Delete the dynamic array myNums at the end. You just need to write part of the program.
You will overload a function named printArray. The function will assign values to each element and...
You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. In C++
in C++ You will overload a function named printArray. The function will assign values to each...
in C++ You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. (6 points) Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables. (4 points)
Multi-Dimensional Arrays Create main class named MultiArray.    Create a method which outputs (prints) all the values...
Multi-Dimensional Arrays Create main class named MultiArray.    Create a method which outputs (prints) all the values in the array. Call this method from each of the other methods to illustrate the data in the array. Note: Be sure to populate, and update the values in the multi-array, and then print the contents of the multi-array (Don't just print the design patterns.) The goal is to practice navigating the multi-array. Declare a multi-dimensional array of integers, which is 10 rows of...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the...
Python HW with Jupyter Notebook Declare a variable named DATA as a dictionary object. Assign the set of key/value pairs shown below. Create a function named iter_dict_funky_sum() that takes one dictionary argument.    Declare a running total integer variable. Extract the key/value pairs from DATA simultaneously in a loop. Do this with just one for loop and no additional forms of looping. Assign and append the product of the value minus the key to the running total variable. Return the funky...
Unix Create a script that will declare an array and assign four values from the command...
Unix Create a script that will declare an array and assign four values from the command line. 1. Use these four values - Paul, Ringo, George, John, - in that order 2. Display the content of the array, displaying the values in this format and this order The first array value is "John" The second array value is "Paul" The third array value is "George" The fourth array value is "Ringo"
Create a random number generator object named myRandom and an integer variable named intRoulette. Set intRoulette...
Create a random number generator object named myRandom and an integer variable named intRoulette. Set intRoulette to be a random number from 0 to 36 (including the numbers 0 and 36). (visual studios 2015) using tryparse
Question 1 Please create three different types of variables and assign three different values into the...
Question 1 Please create three different types of variables and assign three different values into the variables. Please create a new variable and assign the sum of two variables above. Please display all the data (four data here) as a line. Question 2 using Scanner, take three inputs from a user (job level, the number of years in company, and job title) and display yearly bonus percentage based in the following rule: job level : 1 to 10 Job title...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT