2
-7
-2
3.6875. This is easily done on a calculator, just enter the fraction (11/16) then add the integer (3) to the answer.
the square of an integer will always be an integer
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!"
integer = input("Please input an integer greater than 0: ") print(integer)
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)
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
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): ")
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 <enter> 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 <enter> 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.
-2
2
-7
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
#include<iostream> #include<sstream> 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 << "Enter a positive integer (0 to exit): "; string s; cin >> s; if (s[0]=='0') break; stringstream ss; ss << s; if (ss >> num) { cout << "The sum of all squares from 1 to " << num << " is: " << sum_of_squares (num) << endl; continue; } cerr << "Invalid input: " << s << endl; } cout << "Quitting..." << 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...
Reticulated Python