Code is wrong: python parsing warm up.
while(True):
inp_str = input('Enter input string: ')
if (inp_str == 'q'):
break;
while inp_str.find(",")==-1:
print('Error: No comma in string. ')
inp_str=input('Enter input string: ')
s=inp_str.split(",")
print('First word:'+ s[0].strip())
print('Second word:'+ s[1].strip())
print('\n')
This is my code for a problem but the output is wrong and I dont know how to fix it (the top is the output im getting the bottom is what i am supposed to get)
Enter input string: Error: No comma in string. Enter input string: Error: No comma in string. Enter input string: Error: No comma in string. Enter input string: Error: No comma in string. Enter input string: Traceback (most recent call last):
Expected output starts with
Enter input string:
Error: No comma in string.
Enter input string:
Error: No comma in string.
Enter input string:
Error: No comma in string.
Enter input string:
See Image for indentation, Indent it properly
def hasComma(text):
if ',' in text:
return True
return False
def firstNameFirst(text):
if len(text)==0:
return text
string = text.split(",")
if len(string)==2:
return string[1].strip() + " " + string[0]
return string[0]
def divide(x, y):
if isinstance(x, str):
return None
try:
x = float(x)
y = float(y)
return x/y
except:
return None
See Image for indentation, Indent it properly
![main.py saved 1 def hasComma (text); 2 Files D main.py if , in text: return True return False 4. 6 def firstNameFirst(text): if len (text)z0: return text 8 string - text.split(,) if len (string)--2: 10 return string [1].strip) + + string (0] return string[0] 12 13 14 15 16 def divide(x, y): 17 18 19 20 21 if isinstance(x, str): return None try: x = float(x) y- float(y) return x/y 23 24 25 26 27 except: return None](http://img.homeworklib.com/questions/d159cba0-15d3-11ec-a4a4-a9dada7c960c.png?x-oss-process=image/resize,w_560)
Thanks, PLEASE UPVOTE if helpful
Code is wrong: python parsing warm up. while(True): inp_str = input('Enter input string: ') if (inp_str...
This code is not working while True: names = input("Enter input string:") if names == "q": break validlnput ="true" while "," not in names: validlnput="true" print ("Error: No comma in string.") names = input("Enter input string:") # Check for q to terminate if names == "q": exit(0) #set the flag else: validlnput="false" s = names.split(",") print ("First word:",s[0].strip()) print ("Second word:",s[1].strip()) print ("\n") The output should read Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input...
6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...
Python 9.13 LAB: Warm up: Parsing strings (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...
5.9 LAB: Warm up: Parsing strings(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)Examples of strings that can be accepted:Jill, AllenJill , AllenJill,AllenEx:Enter input string: Jill, Allen(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)Ex:Enter input string: Jill Allen Error: No comma in string. Enter input string: Jill, Allen(3) Extract the two words from the input string...
I need help with this exercise, it keeps failing in generating to much results. Warm up: Parsing strings (C++) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the...
What is wrong with my python code. I am receiving this error: Traceback (most recent call last): File "C:/Users/owner/Documents/numberfive.py", line 7, in if age > 18: TypeError: unorderable types: str() > int() My code is age= input("Enter your age:") if age > 18: print("You can vote.") else: print("You can't vote.") if age > 64: print ("You're a Senior Citizen...you deserve two votes") endofprogram = input("Please hit enter to exit from this program:")
while trying to run this in python, i keep getting the error TypeError: int() can't convert non-string with explicit base. any way to fix this? def binaryToDecimal(n): return int(n,2) if __name__ == '__main__': num3 = int(input("Enter value to be converted: ")) print(binaryToDecimal(num3))
I have this code for python: num = int(input()) if num == 0: print('No change') else: dol = num // 100 num %= 100 Quarters = num // 25 num %= 25 Dimes = num // 10 num %= 10 Nickels = num // 5 num %= 5 Pennies = num if dol > 0: if dol == 1: print('1 Dollar') if Dollars > 1: print(dol,'Dollars') if Quarters > 0: if Quarters == 1: print('1 Quarter') if Quarters > 1:...
Python 3 Code: String #1 = Denver, CO, USA String #2 = Denver, CO How would I index to print the string that comes after the second comma? I would like to only print "USA". for string #1, and get an error for string#2.
use python IDEL
Please highlight the answer
Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...