e a Python Program that will shuffle a string and compute its randomness score. The us ng and the number of times they want to shuffle it, and your program is to determine the omness score of each shuffle. Below are the specifics: Your program will first ask the user for a string as well as the number of times they wi ne string. Next, your program will make its first shuffle. This will be done by converting your in ato a list of its characters, and then inputting that list into the shuffle function. Your program will th

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
3 - Assignment
Write a Python Program that will shuffle a string and compute its randomness score. The user will input
a string and the number of times they want to shuffle it, and your program is to determine the
randomness score of each shuffle. Below are the specifics:
• Your program will first ask the user for a string as well as the number of times they wish to shuffle
the string.
• Next, your program will make its first shuffle. This will be done by converting your input string
into a list of its characters, and then inputting that list into the shuffle function.
• Your program will then convert the shuffled list of characters into a string form and print out the
string form.
• Your program will then compute a randomness score based on the differences in ordinal
values between respective positions in the initial string and shuffled string. It will then print
out that randomness score.
• Your program will then shuffle the list of characters again and repeat the process.
Transcribed Image Text:3 - Assignment Write a Python Program that will shuffle a string and compute its randomness score. The user will input a string and the number of times they want to shuffle it, and your program is to determine the randomness score of each shuffle. Below are the specifics: • Your program will first ask the user for a string as well as the number of times they wish to shuffle the string. • Next, your program will make its first shuffle. This will be done by converting your input string into a list of its characters, and then inputting that list into the shuffle function. • Your program will then convert the shuffled list of characters into a string form and print out the string form. • Your program will then compute a randomness score based on the differences in ordinal values between respective positions in the initial string and shuffled string. It will then print out that randomness score. • Your program will then shuffle the list of characters again and repeat the process.
3.1- The Randomness Score
As stated above, the main task of this program is to compute a randomness score based on how different
the inputted string is after being shuffled. To do this, you will implement the following:
• Your calculation will start with the first character of the initial string and the shuffled string.
• You will take the difference between the ordinal value of each character and add that value to
your final score.
• You will then move to the next character and repeat the process until you have gone
through each entire string.
For example, say we input the string "Kevin" and it shuffles into "vKnei". We would then do the
following calculation:
K
75
118
43
K
101
75
26
In
118 110
8
105 101
4.
110 105
Note that when we take the difference between ordinal values, we convert it to its absolute value to
make sure it always stays positive. This means that the total randomness score is 43+26+8+4+5-86.
2
Transcribed Image Text:3.1- The Randomness Score As stated above, the main task of this program is to compute a randomness score based on how different the inputted string is after being shuffled. To do this, you will implement the following: • Your calculation will start with the first character of the initial string and the shuffled string. • You will take the difference between the ordinal value of each character and add that value to your final score. • You will then move to the next character and repeat the process until you have gone through each entire string. For example, say we input the string "Kevin" and it shuffles into "vKnei". We would then do the following calculation: K 75 118 43 K 101 75 26 In 118 110 8 105 101 4. 110 105 Note that when we take the difference between ordinal values, we convert it to its absolute value to make sure it always stays positive. This means that the total randomness score is 43+26+8+4+5-86. 2
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning