1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
grin007 [14]
3 years ago
11

3. Write a program that has the user enter two Strings. Display whether the first String is less than (comes first alphabeticall

y), equal to, or greater than (comes after alphabetically) the first.
Computers and Technology
1 answer:
Citrus2011 [14]3 years ago
4 0

Answer:

The solution code is written in Python 3

  1. firstStr = input("Enter first string: ")
  2. secondStr = input("Enter second string: ")
  3. if(firstStr < secondStr):
  4.    print("The first string comes first alphabetically.")
  5. elif(firstStr > secondStr):
  6.    print("The second string comes first alphabetically.")
  7. else:
  8.    print("The first and second string are same")

Explanation:

Firstly, prompt the user to input two strings (Line 1 - 2).

Next create if else if statement to check if the firstStr is less than, greater than or equal to the secondStr and then print the appropriate message accordingly (Line 4- 9). For example, the program display message "The first string comes first alphabetically." if it find the firstStr is less than secondStr.

You might be interested in
(Analyze scores) Write a program that reads an unspecified number of scores and determines how many scores are above or equal to
Angelina_Jolie [31]

Answer:

#section 1

ls = []  

while True:

   score = float(input('Enter a New score or negative number to exit: '))

   if score < 0:

       break

   else:

       ls.append(score)

   

#section 2

average = sum(ls)/len(ls)

a = [num for num in ls if num >= average]

print('Total Scores Entered: ',len(ls))

print('Average score entered is: ',average)

print('Number of scores above average is: ',len(a))

print('Number of scores below average is:', len(ls)-len(a))

Explanation:

The programming language used is python 3.

#section 1

In this section, an empty list is initialized to hold all the values that will be inputted.

A while loop created which prompts the user to enter an input until a   negative value is entered. This while loop always evaluates to be true until a value less than 0 allows it to break.

Finally, all the scores are appended to the list.

#section 2

In this section the code gets the average by dividing the sum by the number of items in the list.

A new list 'a' is created to hold all the values that are greater than or equal to the average.

Finally, the results are printed to the screen.

I have attached an image with the example stated in your question.

7 0
3 years ago
The steps.txt file contains the number of steps a person has taken each day for a year. There are 365 lines in the file, and eac
Bumek [7]

Answer:

In Python:

file = open('steps.txt', 'r')

readLine = file.readlines()

begin = 0

mdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

print("Month"+"\t\t"+"Average Steps")

for m in range(len(mdays)):

end = begin + mdays[m]

steps = readLine[begin:end]

sumsteps = 0

for s in steps:

 sumsteps = sumsteps + int(s)

 

average = round(sumsteps/mdays[m],1)

print(str(m+1)+"\t\t"+str(average))

begin = begin + mdays[m]

Explanation:

This line opens the step.txt file

file = open('steps.txt', 'r')

This reads the content of the file

readLine = file.readlines()

begin = 0

This initializes the months of the days to a tuple

Mmdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

This prints the header

print("Month"+"\t\t"+"Average Steps")

This iterates through the tuple

for m in range(len(Mmdays)):

This calculates the days in each month

end = begin + Mmdays[m]

This gets the number of steps in each month

steps = readLine[begin:end]

This initializes the number of steps to 0

sumsteps = 0

This iteration sums up the number of steps in each month

<em> for s in steps: </em>

<em>  sumsteps = sumsteps + int(s) </em>

This calculates the average of steps rounded to 1 decimal place  

average = round(sumsteps/Mmdays[m],1)

This prints the calculated average

print(str(m+1)+"\t\t"+str(average))

This calculates the beginning of the new month

begin = begin + Mmdays[m]

8 0
3 years ago
YOU WANT TO DISCARD YOUR OLD COMPUTER AND WANT TO SECURELY ERASE THE DATA FROM YOUR HARD DRIVE. WHAT SOFTWARE CAN YOU USE AND WH
julia-pushkina [17]
Whiping the hard drive.
7 0
3 years ago
Read 2 more answers
The ____ algorithm was the first public key encryption algorithm developed (in 1977 and published for commercial use.
Whitepunk [10]
The RSA Algorithm was developed by and named after the initials of: Ron Rivist, Adi Shamir, and Leonard Adleman while they were working at MIT. It was developed in 1977 and published in 1978.  The algorithm uses the exponentiation modulo in encrypt and decrypt information. 
7 0
3 years ago
Which cell formatting is most likely to use $?
TiliK225 [7]
Currency is the correct answer
4 0
3 years ago
Read 2 more answers
Other questions:
  • The ________ is(are) used to display information on the computer's screen.
    13·1 answer
  • Which three phrases describe a wireframe
    12·1 answer
  • Ok, so this isn't a tech question it's about a game, moomoo.io so don't hate on this if you don't know it, 40 points to whoever
    12·2 answers
  • Which of the following are examples of jobs in the allied health profession? select all that apply.
    8·1 answer
  • What is the web of trust
    7·2 answers
  • 1. Software that is designed to intentionally cause harm to a device, server, or network is A. outware B.loggerware C.
    12·1 answer
  • What is it called when servers on the Internet supply applications as a service, rather than a product
    14·1 answer
  • Explain the different features available in Print command?
    10·1 answer
  • An electronics company develops a line of augmented reality headsets for use in interactive 3d media applications using 5g mmwav
    7·1 answer
  • 3.2.3 What major al able to do? 3.2.4 What major advantage would Printer X have for Tembi who want documents printed? 3.3 If Tem
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!