print("\nNumber\tType\tSquares\tRoots")
print("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _")
for i in range(start,end,step):
sq =i**2
root =math.sqrt(i)
num =(i%2)
print(i, '\t', num, '\t', sq, '\t', root)
print("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ")
I am having a hell of a time trying to get the 'num' to display 'Even' or 'Odd'. I have it to the point where it will display '0' for even and '1' for odd but how am I suppose to assign it to the 'num' as 'Even' or 'Odd'?
Please read
BBCode to learn how to post code.
if i % 2 == 0:
type = "Even"
else:
type = "Odd "
print(type)
type
is built-in function, don't use it as variable name
import math
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
while start > end and end-start>step:
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
print("\nNumber\tType\tSquare\tRoot")
print("_________________________________")
for i in range(start,end,step):
sq =i**2
root =math.sqrt(i)
break
if i % 2 ==0:
type = "Even"
else:
type = "Odd"
print(i, '\t', type, '\t', sq, '\t', root)
print("_________________________________________")
SO input type but the program now runs a single line as opposed to the user inputted numbers...
You haven't made it very clear what you are expecting in terms of output, but a couple of things look problematic:
- Your
for
loop on line 12 doesn't serve any purpose since the break
on line 15 means that lines 13-14 only execute a single time. Do you need to break there?
- If you intend for any of lines 17+ to be within your loop, you need to indent them appropriately (while also deciding what to do with that
break
on line 15).
If I wanted to display Even/Odd for 0/1 I would do it like this
evenodd = ['Even', 'Odd']
for i in range(11):
print(i, 'is', evenodd[i%2])
import math
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
while start > end and end-start>step:
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
print("\nNumber\tType\tSquare\tRoot")
print("_________________________________")
for i in range(start,end,step):
sq =i**2
root =math.sqrt(i)
if i % 2 ==0:
type = "Even"
else:
type = "Odd"
print(i, '\t', type, '\t', sq, '\t', root)
print("_________________________________________")
OUTPUT IS
please enter starting number:1
please enter upper limit number:13
please enter step number:1
Number Type Square Root
_________________________________
12 Even 144 3.4641016151377544
_________________________________________
>>>
but it should display Numbers 1-13 for some reason it stopped displying those numbers in the table?
Tough to say since I cannot see how the code is indented. This code works for me:
import math
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
while start > end and end-start>step:
start= int(input("please enter starting number:"))
end= int(input("please enter upper limit number:"))
step= int(input("please enter step number:"))
print("\nNumber\tType\tSquare\tRoot")
print("_________________________________")
for i in range(start,end,step):
sq =i**2
root =math.sqrt(i)
if i % 2 ==0:
type = "Even"
else:
type = "Odd"
print(i, '\t', type, '\t', sq, '\t', root)
print("_________________________________________")
Output:
Number Type Square Root
_________________________________
1 Odd 1 1.0
2 Even 4 1.4142135623730951
3 Odd 9 1.7320508075688772
4 Even 16 2.0
5 Odd 25 2.23606797749979
6 Even 36 2.449489742783178
7 Odd 49 2.6457513110645907
8 Even 64 2.8284271247461903
9 Odd 81 3.0
10 Even 100 3.1622776601683795
11 Odd 121 3.3166247903554
12 Even 144 3.4641016151377544
_________________________________________
13 is not displayed because range stops before the end value. To include 13 in your calculations your loop should be:
for i in range(start, end+1, step):
I think the reason for this is the most common way to use range is:
for i in range(13):
This will loop 13 times starting with i = 0 and ending with i = 12.
The table will line up better if you use this print:
print(i, type, sq, root, sep = '\t')
def find_min(a,b,c):
min(a,b,c)
def find_max(a,b,c):
max(a,b,c)
def main():
a = int(input("Enter number 1:"))
b = int(input("Enter number 2:"))
c = int(input("Enter number 3:"))
find_min(a,b,c)
find_max(a,b,c)
print("The min is",{find_min})
print("The max is",{find_max})
main()
user input is:
Enter number 1:5
Enter number 2:6
Enter number 3:7
and the output I get is:
The min is {<function find_min at 0x10e618b80>}
The max is {<function find_max at 0x1100591f0>}
I don't understand why im getting that and not the minimum value of 5 and the maximum value of 7?
Your functions do not return a value. That is why you are getting back a function object instead of a number. Calling max(a, b, c) does not make find_max(a, b, c) return the result. Your function needs something like: return max(a, b, c)