ValueError: invalid literal for int() with base 10: 's'
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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

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

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

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education