ValueError: invalid literal for int() with base 10: 's'
Chapter6: Looping
Section: Chapter Questions
Problem 2CP
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1a989ab2-d9cd-4027-8df3-0fe3090b607f%2Fb6e9acb2-5a0e-49b2-b98e-c0dffcd036e4%2F0f69nd_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L