Question

s1 = 'Practice How to Use String Object' Write a python statement that splits the string,...

s1 = 'Practice How to Use String Object'

Write a python statement that splits the string, creating the following list:

['Practice', 'How', 'to', 'Use', 'String', 'Object']

2.

  1. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’:
  2. reply = input("Y or y to continue: ")

    if reply == "Y" and reply == "y":

       print("Y --- <uppercase> has been selected. ")

    else:

       print("y --- <lowercase> has been chosen. ")

    print("… continue running this program …")

  3. Rewrite this statement in python so it only makes one comparison and does not use the or operator. (Hint: use either the upper or lower methods.)

  4. Write a loop that asks the user “Do you want to repeat the program or quit? <R/Q> “. The loop should repeat until the user has entered an R or Q (either uppercase or lowercase).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) Program:

s1 = 'Practice How to Use String Object'
#use split function to split s1 by spaces
listSplit = s1.split(" ")
print(listSplit)

[ Practice, HowtoUse, String. Object

2)

choice = 'r'
while(choice.lower()=='r'):
reply = input("Y or y to continue: ")
if(reply=='y'):
print("Y has been selected")
else:
print("y has been selected")
choice = input("Do you want to repeat the program or quit? <R/Q>: ")

Output:

Y or y to continue: y Y has been selected Do vou want to repeat the proqram or quit? Y or y to continue: Y y has been selecte

Add a comment
Know the answer?
Add Answer to:
s1 = 'Practice How to Use String Object' Write a python statement that splits the string,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • CECS Project 1 RPS (Rock-Paper-Scissors) Game Use python This project asks you to practice . creating...

    CECS Project 1 RPS (Rock-Paper-Scissors) Game Use python This project asks you to practice . creating a new python file using pycharm . doing text- based input and output building your own algorithm using branching and loop Your program should operate as follows It must let the user choose from among three options of rock, paper, and scissors It shall play an honest game of RPS Display the choice the user made . If the user input is not one...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Write a python program that will analyse the string input and print “accept” or “reject” based...

    Write a python program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions  String length 9  3 small alphabet (3 lowercase letter)  3 number (3 digit)  3 big alphabet (3 uppercase letters)  1 st alphabet should be capital  Last alphabet should be a number  Two consecutive alphabets can’t be small Reject if any of the condition is absent

  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • Write a Python program, with comments, to do the following:                        Ask the user to enter...

    Write a Python program, with comments, to do the following:                        Ask the user to enter a string with at least 7 characters. Assume user will enter a valid string. Assign the string to a variable str1 and print str1. In a loop do the following: Update the value of str1 so that the first character from the current value of str1 is removed and added to the end. Print the updated str1.       The loop should continue until updated...

  • Write a Java program that will create an array of Strings with 25 elements. Input Strings...

    Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT