+ 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
8 odpowiedzi
+ 3
fix this line: elif purity == 99.99:
12th Apr 2021, 11:46 PM
Jerry Hobby
+ 1
else purity ==99.99:
26th May 2021, 10:18 AM
Mohamed Ashwak
0
1 decimal point so should be 99.9
24th Nov 2021, 12:40 AM
Thomas Doughty
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
0
10th Aug 2023, 1:34 PM
kia dealer
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
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
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