answersLogoWhite

0


Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: How do you enter integer in python?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can you trap a decimal and let integers pass in python?

Well, say you have a foo function you want to call with input (from raw_input) but ONLY if it is an int. number = raw_input("Enter an integer: ") try: number = int(number) foo(number) except ValueError: print "Number wasn't an integer!"


Write a line of code that asks the python user to input an integer greater than 0 and store this value in a variable and display its value?

integer = input("Please input an integer greater than 0: ") print(integer)


How do I convert a string to an integer in python?

1.>>> x=input("enter data: ")2.enter data: 253.>>> type(x)4.5.>>> y = int(x)6.>>> type(y)7.I used Python 3.0 for this.Else for earlier version, to accept string type input, u should be using "raw_input" instead of "input" only.I made python accept a data and tested its type, which return to be a string (line 4).Then I usedint()to convert the string into a number, which, for testing purpose, I assigned the value to a variable y. (line 5)Testing the type of data that variable y stores, confirms that the string type was converted to an integer type.(line 7)


Code for sum of first natural numbers in python language?

For the first 5 natural numbers (integers):x = 1 + 2 + 3 + 4 + 5print xFor 'n' amount of natural numbers (Python v2 example)n = int(raw_input('Enter max integer: '))count = 0sumn = 0while count < n:sumn = sumn + 1count = count + 1print sumn


How do you write a horoscope program on python?

Hi gys, are you looking to write a program to know the sign depends on the birth date or horoscope on python? write down following codes on python, those will make a nice program. #This program will get the horoscope sign. def getSign(): name = raw_input ("Enter Your Name: ") month = raw_input("Enter Birth Month: ") day = int(raw_input("Enter Birth Day of Month: ")) if month "y": main() letter = raw_input("Go again? (y/n): ")


What is the slope of the line that contains the points -1 8 and 5 -4 Enter your answer as an integer?

-2


What is the slope of the line that contains the points -1 9 and 5 21 Enter your answer as an integer?

2


Given that the slope of a line is 1 7 what is the slope of a line that is perpendicular to it Enter your answer as an integer?

-7


How do you write the code by python?

it depends what type of program you wish to write. python is a very simple programing langauge therefore it doesnt have much room to play with. i mainly use it to work out simple math problems, or use it to calculate thing for games i play, Ex.) This is a program i wrote to work out the Pythagorean therom to find side "C": a = input("Enter Corner Side A\n ") b = input("Enter Corner Side B\n ") c = a*a+b*b import math print math.sqrt(c) raw_input("Press &lt;enter&gt; To Leave Program") input mean that's where you enter your variable, raw input is what you put at the end so it doesnt just run away (NOTE*** THIS IS A PYTHON 2.6.5 SCRIPT, IT WILL NOT WORK ON OTHER VERSIONS OF PYTHON" notice i put ("Press &lt;enter&gt; To Leave Program") this is what it will say before it "runs away". i suggest watching some youtube videos on how to write programs for your version of python. also try using the manual that comes with your version of python. it helps greatly.


Write program that read an integer and display all its smallest factors?

All the smallest factors of a number must be its smallest factor, which for any number is 1, so: loop loop loop print "Enter an integer number: ": input n until num(n) do print "Please enter a number" repeat until n = int(n) do print "Please enter an integer" repeat print "Smallest factor of ":n:" is 1" repeat


What is the C plus plus program to print the sum of all squares from 1 to n?

#include&lt;iostream&gt; #include&lt;sstream&gt; using namespace std; unsigned sum_of_squares (const unsigned max) { if (max==0) return 0; if (max==1) return 1; return sum_of_squares (max-1) + (max*max); } int main () { unsigned num = 0; while (1) { cout &lt;&lt; "Enter a positive integer (0 to exit): "; string s; cin &gt;&gt; s; if (s[0]=='0') break; stringstream ss; ss &lt;&lt; s; if (ss &gt;&gt; num) { cout &lt;&lt; "The sum of all squares from 1 to " &lt;&lt; num &lt;&lt; " is: " &lt;&lt; sum_of_squares (num) &lt;&lt; endl; continue; } cerr &lt;&lt; "Invalid input: " &lt;&lt; s &lt;&lt; endl; } cout &lt;&lt; "Quitting..." &lt;&lt; endl; } Example output: Enter a positive integer (0 to exit): 1 The sum of all squares from 1 to 1 is: 1 Enter a positive integer (0 to exit): 2 The sum of all squares from 1 to 2 is: 5 Enter a positive integer (0 to exit): 3 The sum of all squares from 1 to 3 is: 14 Enter a positive integer (0 to exit): 4 The sum of all squares from 1 to 4 is: 30 Enter a positive integer (0 to exit): 5 The sum of all squares from 1 to 5 is: 55 Enter a positive integer (0 to exit): 6 The sum of all squares from 1 to 6 is: 91 Enter a positive integer (0 to exit): 7 The sum of all squares from 1 to 7 is: 140 Enter a positive integer (0 to exit): 0 Quitting...


What is the slope of the line given by the equation y equals 3x Enter your answer as an integer or fraction in lowest terms?

-2