Question

In: Computer Science

Use python programming to write this code and provide a screen short for the code. 2....

Use python programming to write this code and provide a screen short for the code.

2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop.

You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case letters between 'a' and 'z', inclusive.

Hints

  • The comparison operators >, <, ==, >=, and <= work on strings. For example, 'a' < 'b' evaluates to True; 'j' == 'k' evaluates to False.

Example inputs and outputs

Input

Expected output

'python'

'y'

'antelope'

't'

Solutions

Expert Solution

Program: largestvalue.py

def largestvalue(s): // Function declaration
l=[0 for i in range(26)] // Declare a list for 26 characters;
for i in s: //checks the each character in a string
l[ord(i)-97]=1 //enter the value 1 in each character value represented in list
for i in range(25,-1,-1)://checks the list from backward
if l[i]==1://whenever it found 1
return str(chr(i+97)) //it return the value as string
return 0
s=input() //Reads the input as string
print(largestvalue(s)) // Calls the function and print the return value.

Output:



Related Solutions

Write this code in Python only. Draw a 12" ruler on the screen. A ruler is...
Write this code in Python only. Draw a 12" ruler on the screen. A ruler is basically a rectangular outline with tick marks extending from the top edge. The tick marks should be drawn at each quarter-inch mark. Below the tick marks, your ruler should show large integers at each full-inch position.
PYTHON Write a program for an event organizer. The code can be as short as 7...
PYTHON Write a program for an event organizer. The code can be as short as 7 lines; 9 lines are good enough! a) Request the organizer to enter a participant’s full name in a single input. The input can take two different formats: i. l_name, f_name [1.5 pts] ii. f_name l_name [1.5 pts] b) Print a customized greeting message using the first name, regardless of the formats: “Dear f_name, welcome to the party!” with only the 1 st letter of...
Explain event-driven programming in Python. Give 2 examples of code where event-driven programming is used.
Explain event-driven programming in Python. Give 2 examples of code where event-driven programming is used.
Use Python to solve: show all code: 2) For the last assignment you had to write...
Use Python to solve: show all code: 2) For the last assignment you had to write a program that calculated and displayed the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. The program output looked like this: Balance after year 1 is $ 1060.0 Balance after year 2 is $ 1123.6 Balance after year 3 is $ 1191.02 Balance after year 4 is $ 1262.48 Balance after...
2. Write python code for the below instructions (don’t forget to use the keyword “self” where...
2. Write python code for the below instructions (don’t forget to use the keyword “self” where appropriate in your code): A. Define a Parent Class called Person a. Inside your Person class, define new member variables called name, age, and gender.   Initialize these variables accordingly. b. Define the constructor to take the following inputs: name, age, and gender.   Assign these inputs to member variables of the same name. B. Define Child Class called Employee that inherits from the Person Class...
This is for Python programming, and I am trying to use 2 for loops to ask...
This is for Python programming, and I am trying to use 2 for loops to ask a slaesperson how many of 5 different items they sold, then the program is to calculate the total dollar amount sold. Formatting and all that aside, I am having an issue with the loops not stepping through the 2 lists at the same time. The first loop is taking all 5 entered quantities times the price of the first item, and then all 5...
Using Python programming language, write a LONG piece of code that utilizes the do while function...
Using Python programming language, write a LONG piece of code that utilizes the do while function and the switch statement, please do not make It short, thank you.
Write this code in python Debugging: Use the Debugging Coin Toss code below as the basis...
Write this code in python Debugging: Use the Debugging Coin Toss code below as the basis for this project. Get the program running exactly as it appears in the text. It will run as written. Although it runs, does it run (behave) correctly? That is where you will focus your debugging efforts. Code: import random guess = ' ' while guess not in ('heads', 'tails'):      print('Guess the coin toss! Enter heads or tails: ')      guess = input() toss...
Code in python Write a while loop code where it always starts form 2. Then it...
Code in python Write a while loop code where it always starts form 2. Then it randomly chooses a number from 1-4. If the number 4 is hit then it will write “TP” if the number 1 is hit then it will write”SL”. It will rerun the program every time the numbers 1 and 5 are hit. The code should also output every single number that is randomly chosen. 2 of the same numbers can't be chosen back to back...
Use R programming to resolve this; can you please provide details on the code? A) Create...
Use R programming to resolve this; can you please provide details on the code? A) Create a dataframe – comparativeGenomeSize with the following vectors: > organism<-c("Human","Mouse","Fruit Fly", "Roundworm","Yeast") > genomeSizeBP<-c(3000000000,3000000000,135600000,97000000,12100000) > estGeneCount<-c(30000,30000,13061,19099,6034) B) Print the organism and estGeneCount for Human and fruitfly.(1) C) Add a column to this data frame calculating base pairs per gene. To do this, write a function “genedensity” that takes as arguments the genomesizeBP and estimatedGeneCount information, and calculates from this the estimated bp per gene....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT