Question

while trying to run this in python, i keep getting the error TypeError: int() can't convert...

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))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You are trying to read three inputs as int, but it is actually a string. So, just read the input as a string. There will be no error.

I posted code along with output Screenshot, please do comment if you have any doubts.

Program:

def binaryToDecimal(n):
return int(n,2)
if __name__ == '__main__':
num3 = input("Enter value to be converted: ")
print(binaryToDecimal(num3))

Output Screenshot:

Add a comment
Know the answer?
Add Answer to:
while trying to run this in python, i keep getting the error TypeError: int() can't convert...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...

    I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function

  • THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as...

    THIS IS THE CODE I AM TRYING TO RUN code # def main():       #Reading a as an integer       a = int(input("Enter value for a: "))       #reading b as an interger       b = int(input("Enter value for b: "))       #reading n as an integer       n = int(input("Enter value for n: "))       # displaying if a and b are congruent modulo n, this is True if a and b       #both returns same remainder when divided by n       if a % n == b...

  • Write a python code that takes in an number 0-9 and prints out the word of...

    Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...

  • Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the...

    Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc. def monthString(monthNum): """ Takes as input a number, monthNum, and returns the corresponding month name as a string. Example:...

  • Im writing a c++ program to translate a sentence to pig latin. But I keep getting...

    Im writing a c++ program to translate a sentence to pig latin. But I keep getting an error where it only prints out the "ay" part. Not sure where I'm wrong here. string piglatin(string); string substr(string, int&); int main () //begin main { string input; cout<<"Enter a sentence to convert: "; getline(cin, input); cout<<"Converted to Pig Latin: "<<piglatin(input)<<endl<<endl; //cout << "Search for another value? (Y/N)"; //to convert again system("pause"); return 0; } string piglatin(string input) //piglatin function { int len,...

  • Im trying to flatten out the following list in python code. I keep running into an...

    Im trying to flatten out the following list in python code. I keep running into an 'int is not iterable error' i know this is due to the list being both strings and ints. how do i account for this? list_1 = [1,2,[3,[4,5],6],7,8,['hardware'],[['software'], 'interface']] def flatten (list): flat = [] for sublist in list_1: for item in sublist: flat.append(item) print(flat) return flatten(list_1)

  • Hi I am using python and I keep getting this error with my code. Traceback (most...

    Hi I am using python and I keep getting this error with my code. Traceback (most recent call last): ['1'] Traceback (most recent call last): File "/Users/isabellawelch/Python ish/shuffle.py", line 86, in <module> emp = Employee(emp_data[0], emp_data[1], emp_data[2], emp_data[3], emp_data[4]) IndexError: list index out of range What does it mean and how do i fix it?? from tkinter import Tk, Label, Button, Entry, END employees = [] class Employee: def __init__(self, empno, name, addr, hwage, hworked): self.empno = empno self.name =...

  • In Python, revise this code. define convert(s): """ Takes a hex string as input. Returns decimal...

    In Python, revise this code. define convert(s): """ Takes a hex string as input. Returns decimal equivalent. """ total = 0 for c in s total = total * 16 ascii = ord(c if ord('0) <= ascii <= ord('9'): #It's a decimal number, and return it as decimal: total = total+ascii - ord('0') elif ord('A") <= ascii <= ord('F'): #It's a hex number between 10 and 15, convert and return: total = total + ascii - ord('A') + 10 else...

  • What is wrong with my python code. I am receiving this error: Traceback (most recent call...

    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:")

  • Please assist. I keep getting the error message in the middle screen when I run the...

    Please assist. I keep getting the error message in the middle screen when I run the program on the left. The image on the right is the section of images.py where it's indicating the issue with the .split is. How do I fix this? images.cy - /Users/carrietarpy Downloads/lab9-3/images.py 12.7.18) Python 2.7.18 Shell Python 2.7.15 (v2.7.18:542 102112, Apr 19 2820, 29:48:48) [GCC 4.7.1 Compatible Apple II w 6.3 Clong-FA3.0.57)] on der in Type "help", "copyright', 'credits' or "license()' for more inforyotion...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT