Help with code


Joined
Oct 11, 2022
Messages
1
Reaction score
0
I'm new to coding, but i'm trying to do this excercise from a website, which tells you to print how many 7's are in the number 999 to the power of 999, but my code just prints 0. what's wrong?

Code:
x = 999**999
summa = 0
s = str(x)
for i in range(0,len(s)):
    if s[i] == 7:
        summa = summa + 1
print(summa)
 
Last edited:
Ad

Advertisements

Joined
May 11, 2022
Messages
58
Reaction score
5
so you made the number a string and need to check for string.
Code:
x = 999**999
summa = 0
s = str(x)
for i in range(0,len(s)):
    if s[i] == "7":
        summa = summa + 1
print(summa)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top