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?
- How do I lowercase a string in Python?
- How do you round UP a number?
- How do you round UP a number?
- How do I get a substring of a string in Python?
- Does Python have a string ‘contains’ substring method?
- Convert bytes to a string
- Replacing instances of a character in a string
- Changing one character in a string
- How to read a file line-by-line into a list?
- What is lexicographical order?
- strip(char) on a string
- 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?
- How to convert a string to an integer in JavaScript?
- How to convert an int to string in C?
- Regex not operator
- ValueError: could not convert string to float: id
- Regex not operator
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- Extract a substring using PowerShell
- TypeError: not all arguments converted during string formatting python
- How to convert an int to string in C?
- Maximum and Minimum values for ints
- Maximum and Minimum values for ints
- Extract substring in Bash
- Regex not operator
- print variable and a string in python
- ‘str’ object does not support item assignment
- 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
- Safest way to convert float to integer in python?
- How can I split and parse a string in Python?
- How do I parse a string to a float or int?
- Round a floating-point number down to the nearest integer?
- How to read a text file into a string variable and strip newlines?
- What is the difference between \r\n, \r, and \n? [duplicate]
- Convert bytes to a string
- How to print like printf in Python3?
- string to string array conversion in java
- How to read a text file into a string variable and strip newlines?
- What is the difference between \r\n, \r, and \n? [duplicate]
- Python convert tuple to string
- Regex how to match an optional character
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Split a string into 2 in Python
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- How to print to stderr in Python?
- How do you express binary literals in Python?
- How to print to stderr in Python?
- How to check if the string is empty?
- How to find all occurrences of a substring?
- How do I properly compare strings in C?
- How to remove .html from URL?
- Split string on whitespace in Python
- What is the difference between a “line feed” and a “carriage return”?
- Maximum and Minimum values for ints
- How do I convert a list of ascii values to a string in python?
- How to check whether a str(variable) is empty or not?
- Python TypeError: not enough arguments for format string
- What does the ‘b’ character do in front of a string literal?
- How can I convert a character to a integer in Python, and viceversa?
- 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?
- multiple prints on the same line in Python
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- How can I concatenate str and int objects?
- What does the ‘b’ character do in front of a string literal?
- How to replace all double quotes to single quotes using jquery?
- How can I convert a character to a integer in Python, and viceversa?
- Pythonic way to create a long multi-line string
- Best way to replace multiple characters in a string?
- Convert character to ASCII numeric value in java
- How can I flush the output of the print function?
- Convert columns to string in Pandas
- What does strcmp() exactly return in C?
- Generate random string/characters in JavaScript
- “[ ]” vs. “[[ ]]” in Bash shell