Reputation: 113
The following code is there to add given integer, double and concatenate the string to the user's input integer, double and string respectively. The code is given below, but it gives no output. What's the error in it.
i = 4
d = 4.0
s = 'Hackerrank'
a = int(input())
b = long(input())
c = raw_input()
print(a + i)
print(b + d)
print(s+c)
Kindly point out the errors and let me know the reason for it not working too!
Upvotes: 2
Views: 2553
Reputation: 16224
Consider reading https://realpython.com/learn/python-first-steps/
And to quickly check your code use https://repl.it/languages/python3
You have several errors in your original code. here is the corrected version:
i = 4
d = 4.0
s = 'Hackerrank'
a = int(input())
b = float(input())
c = input()
print(a + i)
print(b + d)
print(s+c)
A little note: You can add a prompt to your calls to input()
so the user knows what to type:
a = int(input("type int "))
b = float(input("type float "))
c = input("please type something")
Finally, if you want to run it with python3 in terminal do:
python3 name_of_file.py
Upvotes: 2
Reputation: 962
Hello ANIRUDH DUGGAL
First read this best website before start Python 3,
1. https://www.tutorialspoint.com/python3/
2. https://docs.python.org/3/tutorial/
3. https://learnpythonthehardway.org/python3/
Difference between python 2 and python 3,
1. http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
2. https://www.quora.com/What-are-the-major-differences-between-Python-2-and-Python-3
Your code perfectly works on version python 2 but if you use the Python 3 so it does not work because in Python 3 is something different syntax so first read Python 3 basic fundamentals(Syntex, inbuilt function,...etc).
Using python2:
#!/usr/bin/python
# Using python 2
i = 4
d = 4.0
s = 'Hackerrank'
a = int(input("Enter the integer number: "))
b = long(input("Enter the long number: "))
c = str(raw_input("Enter the string: "))
print("Output1: %d" % (a + i))
print("Output1: %f" % (b + d))
print("Output1: %s" % (s+c))
Using python3:
#!/usr/bin/python
# Using python 3
i = 4
d = 4.0
s = 'Hackerrank'
a = int(input("Enter the integer number: "))
b = float(input("Enter the long number: "))
c = str(input("Enter the string: "))
print("Output1: %d" % (a + i))
print("Output1: %f" % (b + d))
print("Output1: %s" % (s+c))
I hope my answer is useful for you.
Upvotes: 0
Reputation: 154
in python 3 it is just input() and change the long to float
Upvotes: 0