asks to raise the number to 9
You say one thing and your code says another. When it does pow(9,numero)
, it is raising 9 to a number , not a number to 9. Let's see things in two ways.
Last character, raising a given number to 9
Open a python file or prompt and paste the following:
for i in range(100):
print(i, str(i**9)[-1])
What we are doing is showing a number from 0 to 99, and the last digit of that number when raised to 9.
You will find such a result:
75 5
76 6
77 7
78 8
79 9
80 0
81 1
82 2
83 3
...
Can you see any pattern there? The last digit of each number raised to 9 is the last digit of the number itself . It got easier, did not it? We can simplify the following code block:
numero = input()
print(numero[-1])
Last character, raising 9 to a given number
If the problem really is about raising 9 to a given number as in your code, we can try to find out if there is any other pattern.
for i in range(100):
print(i, str(9**i)[-1])
Result:
56 1
57 9
58 1
59 9
60 1
61 9
62 1
...
Now, Batman. It seems we have another standard. For odd numbers the answer is 9
, and for pairs the answer is 1
. Our code looks like this:
numero = int(input())
print(1 if numero % 2 == 0 else 9)
Voila! We solved the problem without calculating a single power.
Moral of the story:
It may be worth studying the problem superficially before going straight into the solution.