There are two ways to fix the problem which is caused by the last print
statement.
You can assign the result of the str(c)
call to c
as correctly shown by @jamylak and then concatenate all of the strings, or you can replace the last print
simply with this:
print "a + b as integers: ", c # note the comma here
in which case
str(c)
isn’t necessary and can be deleted.
Output of sample run:
Enter a: 3 Enter b: 7 a + b as strings: 37 a + b as integers: 10
with:
a = raw_input("Enter a: ") b = raw_input("Enter b: ") print "a + b as strings: " + a + b # + everywhere is ok since all are strings a = int(a) b = int(b) c = a + b print "a + b as integers: ", c
Related Posts:
- Converting integer to string in Python
- working of \n in python [duplicate]
- How to remove punctuation in python?
- How to convert an int to string in C?
- How to get the filename without the extension from a path in Python?
- sprintf like functionality in Python
- n-grams in python, four, five, six grams?
- Alphabet range in Python
- How can I print variable and string on same line in Python?
- What is lexicographical order?
- What is the purpose of the return statement?
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Reverse a string in Python
- How do I compare two strings in python?
- ValueError: could not convert string to float: id
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- Maximum and Minimum values for ints
- Maximum and Minimum values for ints
- Regex not operator
- print variable and a string in python
- How do I append one string to another in Python?
- How do I append one string to another in Python?
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- How do I parse a string to a float or int?
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Best way to strip punctuation from a string
- How to print to stderr in Python?
- How to print to stderr in Python?
- How to check if the string is empty?
- Split string on whitespace in Python
- Maximum and Minimum values for ints
- How to check whether a str(variable) is empty or not?
- Ignoring upper case and lower case in Java
- How to convert an int to string in C?
- How to add a string in a certain position?
- This can be done without regex:
- How can I convert a character to a integer in Python, and viceversa?
- Pythonic way to create a long multi-line string
- Convert columns to string in Pandas
- What does strcmp() exactly return in C?
- “[ ]” vs. “[[ ]]” in Bash shell
- How to delete a character from a string using Python
- Remove the first character of a string
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- C – The %x format specifier
- Lua string.format options
- How to convert integer to string in C?
- How to check if a string is a substring of items in a list of strings?
- Best way to replace multiple characters in a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How to convert string to binary?
- How to print instances of a class using print()?
- Converting from a string to boolean in Python?
- How do I check if there are duplicates in a flat list?
- int cannot be converted to string?
- Mips how to store user input string
- bash : Bad Substitution
- Convert hex string to int in Python
- How can I check if character in a string is a letter? (Python)
- Converting String Array to an Integer Array
- How can I find the first occurrence of a sub-string in a python string?
- How to concatenate items in a list to a single string?
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Properly formatted multiplication table
- How to assign multiple lines string in Powershell Console
- How to get a function name as a string?
- Pandas error “Can only use .str accessor with string values”
- LC-3 STR with R1 as offset
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- Converting a string to an integer on Android
- How to repeat a string with spaces?
- AttributeError: ‘str’ object has no attribute ‘items’
- How do I print my Java object without getting “SomeType@2f92e0f4”?
- How to pad zeroes to a string?
- How can I process each letter of text using Javascript?
- How do I convert a string to a double in Python?
- How can I copy a Python string?
- How to strip a specific word from a string?
- Converting integer to binary in python
- Checking if a string can be converted to float in Python
- Passing string to a function in C – with or without pointers?
- How to get ° character in a string in python?
- Lua String replace
- Trim a string in C [duplicate]
- Python cant convert ‘list’ object to str error [closed]
- In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python
- When to use %r instead of %s in Python? [duplicate]
- Python – difference between two strings