+ 1

24K Magic - Boolean logic- only challenge 7 not working what should i do to improve my code ?

purity = float(input()) if purity >= 75.0 and purity < 83.3 : print("18K") elif purity >= 83.3 and purity < 91.7 : print("20K") elif purity >= 91.7 and purity < 99.9 : print("22K") elif purity == 99.99: print("24K")

12th Apr 2021, 10:50 PM
ahmed dhamen
ahmed dhamen - avatar
9 Antworten
+ 3
fix this line: elif purity == 99.99:
12th Apr 2021, 11:46 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
else purity ==99.99:
26th May 2021, 10:18 AM
Mohamed Ashwak
Mohamed Ashwak - avatar
0
1 decimal point so should be 99.9
24th Nov 2021, 12:40 AM
Thomas Doughty
Thomas Doughty - avatar
0
To improve the code and fix the issue with challenge 7, you need to update the conditions in your if-elif statements. Currently, you have specified ranges using inequalities, but it seems like you have missed the range for 24K purity. To include the 24K purity range, you can modify the code as follows: purity = float(input()) if purity >= 75.0 and purity < 83.3: print("18K") elif purity >= 83.3 and purity < 91.7: print("20K") elif purity >= 91.7 and purity < 99.9: print("22K") elif purity >= 99.9 and purity <= 100.0: # Include the range for 24K purity print("24K") else: print("Invalid purity value") By adding the condition purity >= 99.9 and purity <= 100.0, you ensure that any purity https://www.mcdvoice.onl/ value equal to or greater than 99.9 is considered 24K. Additionally, an else statement is included to handle any invalid purity value that doesn't fall within the specified ranges.
8th Jun 2023, 11:29 AM
xhuskso bzisks
xhuskso bzisks - avatar
0
The Grateful Dead performed live at the Stadium, U.C Santa Barbara on May 20, 1973. This concert is well-known among fans for its impressive setlist and high-energy performances. The show featured classic Grateful Dead songs such as "Bertha," "Box of Rain," "China Cat Sunflower," "I Know You Rider," and "The Other One." The concert has been widely circulated among fans and is available for streaming and download on various websites, including the Internet Archive and YouTube. 24K Magic - Boolean logic- only challenge 7 not working what should i do to improve my code ? Based on the code snippet provided in the search results, it appears that the issue with Challenge 7 in the 24K Magic Boolean logic exercise may be related to the input value. Here's the code snippet for reference: purity = float(input()) if purity >= 75.0 and purity < 83.3: print("18K") elif purity >= 83.3 and purity < 91.7: print("20K") elif purity >= 91.7 and purity < 99.9: print("22K") elif purity == 99.99: print("24K") One possible solution to improve the code is to add some error handling to https://www.kdealer.one/ ensure that the input value is within the expected range. For example, you could add a check to make sure that the input value is a valid number between 0 and 100: purity = input("Enter the purity of the gold (0-100): ") try: purity = float(purity) if purity < 0 or purity > 100: raise ValueError except ValueError: print("Invalid input. Please enter a number between 0 and 100.") exit() if purity >= 75.0 and purity < 83.3: print("18K") elif purity >= 83.3 and purity < 91.7: print("20K") elif purity >= 91.7 and purity < 99.9: print("22K") elif purity == 99.99: print("24K") else: print("Invalid input. Please enter a number between 0 and 100.") This code adds a try-except block to catch any errors that may occur when trying to convert the input value to a float. It also checks that the input value is within the expected range before proceeding with the rest of the code.
10th Aug 2023, 1:34 PM
kia dealer
kia dealer - avatar
0
It looks like you have a simple Python script to determine the karat of gold based on its purity. Your code is using the input() function to get the purity value as a float and then uses conditional statements to check the range of purity and print the corresponding karat. Here's a suggestion to improve the readability of your code: purity = float(input("Enter the gold purity percentage: ")) if 75.0 <= purity < 83.3: print("18K") elif 83.3 <= purity < 91.7: print("20K") elif 91.7 <= purity < 99.9: print("22K") elif purity == 99.99: print("24K") else: print("Invalid purity value. Please enter a value between 75.0 and 99.99.") I made a couple of changes: Used the input() function to prompt the user for input. Simplified the range conditions in the if and elif statements for better readability. Added an else statement to handle cases where the purity value is not within any of the specified ranges. This should make your code more user-friendly and handle a wider range of purity values. https://www.crediblebh.life/
30th Nov 2023, 1:42 PM
crediblebh blog
crediblebh blog - avatar
0
Based on how pure the gold is, it looks like you have a simple Python tool that can tell you its karat. Your code uses the input() method to get the raw purity value as a float. It then checks the purity value against a range and prints the karat that matches. Take a look at this idea to make your code easier to read: enter("Enter the gold purity percentage:")) when 75.0 is less than or equal to 83.3, print "18K"; if 83.3 is greater than or equal to 91.7, print "20K" in case 91.7 is less than or equal to 99.9, print "22K" if pure == 99.99: print("24K") else: print("Pureness value is not valid. "Please enter a number between 75.0 and 99.99." I changed a few things: Used the function input() to ask the user for information. Made the range conditions in the if and elif lines easier to read by making them less complicated. I added an else statement to deal with situations where the purity number is not in any of the ranges that were given. This should help people use your code better and let it handle more purity values. https://kdealer.online/
23rd Dec 2023, 5:45 PM
KDealer
KDealer - avatar
0
I thought I would find several playlists of metal. But I'm gonna try some anyway :) https://www.mcdvoice.help/
26th Jan 2024, 6:11 AM
Mcdvoice
Mcdvoice - avatar