Question

3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along w
Program 2: Name this program listPractice.py 1. Start a new Python program. 2. Add header comments using this template: progr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Program 1

# input a string from user
s1=input("Enter a string:")

# print the length of the string
print("Length of the string = ",len(s1))

# print first character of the string
print("First character of the string = ",s1[0])

# print the last character of the string
print("Last character of the string = ",s1[-1])

# Program 2
# Create an empty list
mylist=[]

# input 5 float numbers
for i in range(5):
num=float(input())
mylist.append(num)
  
# print the sum of the list elements
print("Sum = ",sum(mylist))

# print the minimum element
print("Minimum element = ",min(mylist))

# print the maximum element
print("Maximum element = ",max(mylist))

# print the average of the list elements
print("Average = ",sum(mylist)/len(mylist))

# remove the last element of the list
mylist=mylist[:-1]

# print the list
print("Mylist = ",mylist)

In [7]: # Proyrum 1 1 input a string from user s1=input(Enter a string:) # print the length of the string print(Length ofIn [12]: # Program 2 # Creole un emply list Trylist=[] #input 5 float numbers for i in range(5): riunfloal(input()) mylist.ap

Add a comment
Know the answer?
Add Answer to:
3. Write Python statements that will do the following: a) Input a string from the user....
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 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...

  • Python installation: Install Python 3 as described here. (We will work with Windows PC's.) Launch IDLE...

    Python installation: Install Python 3 as described here. (We will work with Windows PC's.) Launch IDLE Enter the program listed in the attached file: "First program in IDLE". Save a "ProgA.py" Debug until code runs correctly. Take a screenshot of the correct output Save as "YourLastName_IDLE1.png" Upload here How do you debug # First Python Program #Fill date here # Name: Fill name here # _________________________ first = input("Enter first name:") last = input("Enter last name:") print("Hello " + first...

  • 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...

  • Using python 1. Write a program that read a line of input as a string and...

    Using python 1. Write a program that read a line of input as a string and print every second character of the string

  • Write a Python script in that will prompt the user to enter a string. After the...

    Write a Python script in that will prompt the user to enter a string. After the user enters their string print its length and the ordinal value of the first, third, and seventh character. Assume the input will be of sufficient length. Use "nice" input and output

  • Please do it with C++. Thanks:) Write a program that reads a string and a character...

    Please do it with C++. Thanks:) Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input. Sample run: Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.

  • Write a C++ program to get an input string from the user, and output the string...

    Write a C++ program to get an input string from the user, and output the string in uppercase letters. Use a dynamic character array to store the string. ?(this can be from any input file, there is no specific file.)

  • Write code in python for following Use queue to implement it Implement a decryption method String...

    Write code in python for following Use queue to implement it Implement a decryption method String decrpt(String s) to decrypt a number sequence (stored in a string s). The decryption algorithm works as follows: Delete the first element of the sequence Move the first element of the sequence to the end Delete the first element of the sequence Move the first element of the sequence to the end …. This process keeps running until all element in the sequence has...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • This program will require you to create a basic parser for an input string that is...

    This program will require you to create a basic parser for an input string that is somewhat like Python. Python has an older parser module and a newer ast module to manage pure Python syntax, but they won't be useful here. The program will read a data string, identify the control characters, and print out the overall structure of the string. Here's an example Input String: [{1}] Output: Number inside a dictionary inside a list Here are some basic rules...

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