ValueError: invalid literal for int() with base 10: 's'

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 1CP
icon
Related questions
Question
What is the error ?
Source Run Debug Consoles Projects Tools View Help
C:\Userslosama\Desktop
besktop\untitiedo.py
S-40.py X untitledo.py*
Source Console
Object
test.bt X
guthor: osama
Usage
Here you can get help of any object by pressing Ctri+n ond of
either on the Editor or the Console
#Opening the file
Help can also be shown automatically after writing a le p e
next lo an object You can activate this behavior in Preferences
Help.
with open("test.txt",'r') as file:
a = file.readlines()
alist-[]
for i in a:
#adding numbers to list
alist.append (i.rstrip('\n'))
#Declaring required variables
total even -0
total_odd
New to Spyder? Read our tutoral
= 0
Count = 0
#Iterating through the list
- for i in alist:
Varlable explorer Help Plots Files
count+=1
O
Console 2/A X
even_count = 0
odd_count = 0
for j in i:
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
if j l= " ":
#Keeping count of odd and even numbers
IPython 7.12.0 -- An enhanced Interactive Python.
if(int(j)%2m0):
even_count+-1
total_even + 1
else:
odd count+1
total odd+=1
In [1]: runfile('C:/Users/osama/Desktop/untitledo.py', wdir='C:/Users/osama/Deshto2
Traceback (most recent call last):
I
File "C:\Users\osama\Desktop\untitledo.py", line 29, in <module
if(int(j)%2==0):
#Printing the result
print ("In Line #",count, "there are", even_count, "even digits and",odd_count, "odd digits. ")
35
ValueError: invalid literal for int() with base 10: ''
36
37
38
SPrinting the result
In [2]:
39
print("In total there are", total_even, "even digits and", total_odd, "odd digits. ")
print("The probability of even digits is: ", round((total_even)/(total_even+total_odd),2))
print ("The probability of odd digits is: ", round ((total_odd)/(total_even+total_odd),2))
41
42
43
44
Python corIsole History
Transcribed Image Text:Source Run Debug Consoles Projects Tools View Help C:\Userslosama\Desktop besktop\untitiedo.py S-40.py X untitledo.py* Source Console Object test.bt X guthor: osama Usage Here you can get help of any object by pressing Ctri+n ond of either on the Editor or the Console #Opening the file Help can also be shown automatically after writing a le p e next lo an object You can activate this behavior in Preferences Help. with open("test.txt",'r') as file: a = file.readlines() alist-[] for i in a: #adding numbers to list alist.append (i.rstrip('\n')) #Declaring required variables total even -0 total_odd New to Spyder? Read our tutoral = 0 Count = 0 #Iterating through the list - for i in alist: Varlable explorer Help Plots Files count+=1 O Console 2/A X even_count = 0 odd_count = 0 for j in i: Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. if j l= " ": #Keeping count of odd and even numbers IPython 7.12.0 -- An enhanced Interactive Python. if(int(j)%2m0): even_count+-1 total_even + 1 else: odd count+1 total odd+=1 In [1]: runfile('C:/Users/osama/Desktop/untitledo.py', wdir='C:/Users/osama/Deshto2 Traceback (most recent call last): I File "C:\Users\osama\Desktop\untitledo.py", line 29, in <module if(int(j)%2==0): #Printing the result print ("In Line #",count, "there are", even_count, "even digits and",odd_count, "odd digits. ") 35 ValueError: invalid literal for int() with base 10: '' 36 37 38 SPrinting the result In [2]: 39 print("In total there are", total_even, "even digits and", total_odd, "odd digits. ") print("The probability of even digits is: ", round((total_even)/(total_even+total_odd),2)) print ("The probability of odd digits is: ", round ((total_odd)/(total_even+total_odd),2)) 41 42 43 44 Python corIsole History
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage