The following pseudocode describes how to obtain the name of a day, given the day number (0 = Sunday, 1 = Monday, and so on.)
Declare a string called names containing "Sun MonTueWedThuFriSat".
Compute the starting position as 3 x the day number.
Extract the substring of names at the starting position with length 3.
Check this pseudocode, using the day number 4. Draw a diagram of the string that is being computed, similar to Figure 3.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Using MIS (10th Edition)
Digital Fundamentals (11th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Design a program with an algorithm that will take a string from the user and then decide if each character in that string is unique. For example, if you ask the user to enter a string and that user enters the world ‘hello’, the result of the algorithm implementedshould return ‘false’ or ‘not unique’. If the user enters a string such as the word ‘phone’ the program will return ‘true’ or ‘unique’ since every character in the word phone is unique and is not repeated. An example of this program follows: Output should show as : enter a string rizma This string has all the unique characters would u like to continue?(y for yes n for no) y Enter a string waali This string is not unique Your code should work for all strings and essentially all characters, as many examples will be tested.arrow_forwardWrite a program using a codeblock that consists of the following algorithm: num1 =4, num2= 4* 5-11, sale = 0.02 * 1000, first =‘D’, str = “It is a sunny day”. .Your program has to display the results for num1, num2, sale, first and stringarrow_forwardIn python: Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0 n is different than N.arrow_forward
- python Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times the character appears in the phrase. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0 n is different than N. c = input()words = input() count = 0 for x in words: if x == c: count = count + 1 print(count)arrow_forwardIN PYTHON Given a number of petals, print a string which repeats the phrases "Loves me" and "Loves me not" for every alternating petal. The last phrase printed (for the last petal picked) should be in all caps. Remember to include a comma and space between phrases, as shown in examples below. Sample Input 1 3 Sample Output 1 "Loves me, Loves me not, LOVES ME" Sample Input 2 1 Sample Output 2 "LOVES ME"arrow_forward(Computation) A magic square is a square of numbers with N rows and N columns, in which each integer value from 1 to (N * N) appears exactly once, and the sum of each column, each row, and each diagonal is the same value. For example, Figure 7.21 shows a magic square in which N=3, and the sum of the rows, columns, and diagonals is 15. Write a program that constructs and displays a magic square for a given odd number N. This is the algorithm:arrow_forward
- Write a program that generates 1,000 lowercase letters randomly, counts the occurrence of each letter, and displays a histogram for the occurrences, as shown in Figure 10.16a.arrow_forwardA very known application in natural language processing is to extract information from a given text. In this lab, you will be able to extract some emotions (Sad and Happy) from a given string and calculate the score of each emotion. You will be given below the words that express sadness, anger, and happiness. For each word, you will be given weight as well, so that when you are calculating for example the score for sadness in the text (string), you can use this formula:arrow_forwardConsidering string manipulations, create a Python program that asks for two string input, S1 and S2, and displays the two strings in alphabetical order. Assume that the two strings are not empty.arrow_forward
- Write a python program to read a string from the user. The pattern of the string should be as given below. must have 3 words each has 4 letters only. The first two words are separated by "@" and the third word is separated by white space. For example, “utas@oman mail”. Read the string until it matches the pattern. If the entered string matches the pattern, print “Valid String”, replace the white space with "." and print the string after replaced before exiting the program. If the string does not match the pattern, print "Invalid string.. Enter again" and prompt the user again to enter the string.arrow_forwardTwo words are anagrams if they contain all of the same letters, but in a different order. For example, “evil” and “live” are anagrams because each containsone ‘e’, one ‘i’, one ‘l’, and one ‘v’. Create a program in python that reads two strings from the user, determines whether or not they are anagrams.arrow_forwardIN PYTHON!! Get an input string, at least 7 characters in length, from the user. If the string is less than 7 characters, have them enter it again. Repeat until you have a proper input string. Perform each of the following transformations on that string and print the result. I've included the expected result for each step, based on the input string "testing". extract the first 3 characters ("tes") extract the last 5 characters ("sting") extract the middle 2 characters (use // 2 to determine the middle) ("st") extract every other character ("tsig") reverse the string ("gnitset") extract 1/3 of the characters (use // 3 to determine the step size) ("tsig") "encrypt" the string by reversing it, then swapping the first and last half ("tsetgni") The complete output for "testing" should look like: tes sting st tsig gnitset tsig tsetgniarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT