• Register
1 vote
118 views

Problem :

The program supposed to take in two names, and if they are the same length it should check if they are the same word.

But i am getting below error in python

python typeerror: not all arguments converted during string formatting

6 5 3
6,930 points

Please log in or register to answer this question.

2 Answers

1 vote

Solution:

The correct way to use traditional string formatting using the '%' operator is to use a printf-style format string (Python documentation for this here: http://docs.python.org/2/library/string.html#format-string-syntax):

Further Readings:

https://github.com/getpelican/pelican/issues/2489

9 7 4
38,600 points
1 vote

Solution:

If I understand correctly, you are having the String formatting issue. Correct me if I am wrong. It is hard to get the problem and provide a solution without seeing the code snippet. Please attach the code snippet with your question from your next post. As per my understanding, the right way formatting a string in python3 is:

print("Hello {}, your balance is {}.".format("Adam", 230.2346))

And as long as the whole program is concerned you don’t need to use string formatting in your codes. You can try this:

first_name = input("\nEnter the frist name")
second_name = input("\nEnter the second name")
if len(first_name) == len(second_name):
	if first_name == second_name:
		print("\nSame name")
	else:
		print("Not the same name")

Good luck!

13 9 6
94,240 points

Related questions

0 votes
1 answer 8 views
8 views
Problem: The program is supposed to take in two names, and if they are the same length it should check if they are the same word. If it's the same word it will print "The names are the same". If they are the same length but with different letters it will print "The names are different ... than '{1}'"% name1, name2) elif len(name1) < len(name2): print ("'{0}'is longer than '{1}'"% name2, name1)
asked Feb 16 Mashhoodch 13k points
0 votes
1 answer 22 views
22 views
Problem: One of the main features of the Java language keeps you in check so that your programs work in the way that you intend. You may encounter an error saying &ldquo;not all arguments converted during string formatting&rdquo; How i working with strings.
asked Dec 2, 2020 Mashhoodch 13k points
0 votes
1 answer 45 views
0 votes
1 answer 8 views
8 views
Problem: after upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Mar 16 ummesalma 24.5k points
0 votes
1 answer 2.5K views
2.5K views
Problem : I am facing the issue in passing a function as a parameter to another function as follows typeerror: int() argument must be a string, a bytes-like object or a number, not 'nonetype'
asked Nov 18, 2019 peterlaw 6.9k points
0 votes
1 answer 21 views
21 views
Problem: I'm playing with both learning python and trying to get github issues into a readable form. Using the advice on How can I convert JSON to CSV? I came up with this: import json import csv f=open('issues.json') data = json.load(f) f.close() f=open("issues.csv" ... item["labels"], item["state"]]) Where "issues.json" is the json file containing my github issues. When I try to run that, I get
asked Feb 15 Mashhoodch 13k points
0 votes
1 answer 42 views
42 views
On making a small program for math there returned an error "TypeError: 'NoneType' object is not subscriptable. Never before has been seen, this error, so no idea what it means. import math print("The format you should consider:") print str("value 1a")+str(" + ")+ ... /Nathan/Documents/Python/New thing", line 16, in <module> a = lista[1] - lista[0] TypeError: 'NoneType' object is not subscriptable
asked Oct 24, 2020 psandprop 2.4k points
1 vote
1 answer 5 views
5 views
Problem: Help is required from some body to convertthis. Typeerror: can't convert 'float' object to str implicitly.
asked Mar 28 PkGuy 13.1k points
0 votes
1 answer 22 views
22 views
Problem: I have this python program that adds strings to integers: a = raw_input("Enter a: ") b = raw_input("Enter b: ") print "a + b as strings: " + a + b a = int(a) b = int(b) c = a + b str(c) print "a + b as integers: " + c I get this error: Python: TypeError: cannot concatenate 'str' and 'int' objects How can I add strings to integers?
asked Feb 17 Mashhoodch 13k points
0 votes
1 answer 3 views
3 views
Problem: Please help me &hellip; how can I solve it? typeerror: 'dict_items' object does not support indexing
asked 6 days ago Ifra 24.4k points