Question

# Python Please help me convert the input values to float values Code works, but the...

# Python
Please help me convert the input values to float values
Code works, but the values printed need to be floats like 77.0 etc.

  
j_list = []
k_list = []
c_list = []
  
# Enter scores for Jean
print("Please enter Jean's scores one by one. ")
for i in range(4):
j_list.append(eval(input()))
print("Jeans scores:", j_list)
  
# Enter scores for Kayla
  
print("Please enter Kayla's scores one by one. ")
for i in range(4):
k_list.append(eval(input()))
print("Kayla scores: ", k_list)
  
# Enter scores for Connie
print("Please enter Connie's scores one by one. ")
for i in range(4):
c_list.append(eval(input()))
print("Connie scores: ", c_list)
  
# merging everything to a single list

all_scores = [j_list, k_list, c_list]
print("All scores", all_scores)
  
# adding one to the scores of each skaters using nested list

for i in range(len(all_scores)): #loop
for iterating through the main list
for j in range(len(all_scores[i])): #loop
for iterating through the sub list
all_scores[i][j] += 1# adding 1 to scores
print("All scores after extra point:", all_scores)
  
# now we will sort the values in the same way as previous

for i in all_scores:
i.sort()
print("Scores after sorting:", all_scores)
print(all_scores)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As you said the code was running well. To get your desired output, which was to convert input values to float type, you just need to change the input type from eval to float. Just this one thing will do the work. If you have any doubts regarding my answer, please tell me in the comments below. I would be very happy to help you.

NOTE: Please adjust the indentation of my code while copying according to the one in the screenshot, as the Chegg platform removes all indentation from code.

MODIFIED CODE TO COPY:

j_list = []
k_list = []
c_list = []
  
# Enter scores for Jean
print("Please enter Jean's scores one by one. ")
for i in range(4):
j_list.append(float(input()))
print("Jeans scores:", j_list)

# Enter scores for Kayla
print("Please enter Kayla's scores one by one. ")
for i in range(4):
k_list.append(float(input()))
print("Kayla scores: ", k_list)
  
# Enter scores for Connie
print("Please enter Connie's scores one by one. ")
for i in range(4):
c_list.append(float(input()))
print("Connie scores: ", c_list)
print()
# merging everything to a single list
all_scores = [j_list, k_list, c_list]
print("All scores", all_scores)
  
# adding one to the scores of each skaters using nested list
for i in range(len(all_scores)): #loop for iterating through the main list

for j in range(len(all_scores[i])): #loop for iterating through the sub list

all_scores[i][j] += 1# adding 1 to scores
print("All scores after extra point:", all_scores)
  
# now we will sort the values in the same way as previous

for i in all_scores:
i.sort()
print("Scores after sorting:", all_scores)

SCREENSHOT OF CODE:

SCREENSHOT OF OUTPUT:

Add a comment
Know the answer?
Add Answer to:
# Python Please help me convert the input values to float values Code works, but the...
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
  • Below is my code please help me edit it so in the beginning it ask for Press any key to start Tas...

    below is my code please help me edit it so in the beginning it ask for Press any key to start Task n, where n is the task number (1, 2, or 3,4). I already wrote the code for the 4 task. Also please write it so when 1 code is finish running it return to the prompt where it ask to run another task #task 1 list1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','.',',','?'] morse = ['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','-----','.----','..---','...--','....-','.....','-....','--...','---..','----.','.-.-.-','--..--','..--..'] inp = input("Enter original text : ")...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • this python code below is to find the longest common subsequence from two input string !!!...

    this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...

  • in python would you please help me to keep this code as in a simple and...

    in python would you please help me to keep this code as in a simple and easy code to follow please I want the code to run like first line of the letters ['B', 'C', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD'] ['B', 'BC', 'BCB', 'BCBD', 'C', 'CB', 'CBD', 'BD', 'D'] word="BCBD" lst=[] for i in range(len(word)): for j in range(i+1,len(word)+1): if word [i:j] not in lst: lst.append(word[i:j]) print(lst)

  • Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:")...

    Convert this code written in Python to Java: username=input("please enter a username") password=input("please enter a password:") def is_a password(password):     count_uppercase, count_lowercase= 0, 0     for characters1 in password:         if characters1.isupper():         count_uppercase += 1         if characters1.islower():         count_lowercase += 1     is_password is good = True     if len(password) <= 7:         print "Passwords must be at least 8 characters long"     is_password is good = False     if count_uppercase < 1:         print "Your password must...

  • Create a graph in python for a given input series without using any libraries

    I was asked this question:Given any input series a corresponding graph must be generated without the use of any libraries.After, trying my best, I arrived at this solution to which they replied it had a logical issue.# Create the matrix print("Enter the sequence with spaces: ") arr = list(map(int, input().split())) count = len(arr) rows = int(sum(arr))  cols = int(sum(arr) + 4) content = [[" "]*cols for _ in range(rows)] maxq = 0 maxp = 0 content[0][0] = "/" # Apply the positions in the matrix p = 0 q = arr[0] k = 0 for l in range(q):     if (k != q):         content[k][p] = "/"         p = p + 1         k = k + 1 p = q flag = 1 i = 0 j = 0 k = 0 c = 0 temp = 0 r = 0 flag = 1 for i,j in enumerate(arr):     c = c + 1     if c < count:         k = arr[i+1]     else:         k = 0     if arr[i]:         if flag == 1:             content[q][p] = "/\\"             if maxq < q:                 maxq = q                 maxp = p             qori = q             pori = p             p = p + k             temp = q - k...

  • Using python 3.6 How do I incorporate 0 or negative input to raise an error and...

    Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...

  • Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk()...

    Here is my code for minesweeper in python and it has something wrong. Could you please help me to fix it? import tkinter as tk import random class Minesweeper: def __init__(self): self.main = tk.Tk() self.main.title("mine sweeper") self.define_widgets() self.mines = random.sample( [(i,j) for i in range(25) for j in range(50) ],self.CustomizeNumberOfMines()) print(self.mines) self.main.mainloop() self.CustomizeNumberOfMines() def define_widgets(self): """ Define a canvas object, populate it with squares and possible texts """ self.canvas = tk.Canvas(self.main, width = 1002, height=502, bg="#f0f0f0") self.canvas.grid(row=0, column=0) self.boxes =...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • how to make my code of python work probely my q is how to write a...

    how to make my code of python work probely my q is how to write a code to find the average actual water level, average error by using python and my program should be flexible where user can select the column no. If you can see in the main program, it asked which column to know the maximum or average, the column number is passed to the function. The function should look which column to do. #THIS PROGRAMMING IS ABLE...

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