Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

python (easy task help)

I also ran into trouble with another task. I need to write a program that asks the user for 2 words, if they are the same it prints "same", if not it prints the word that has more letter "e" in it.

1)So I start it off with this right:
word1 = raw_input("Enter the first word")
word2 = raw_input("Enter the second word")

2)Now if they are the same it should be
if word1 == word2
print ("Same")

3)How do i make it check which word has more letters "e" in it?
by same you mean the same amount of letters or the exact same word?
(Feb 22, 2016 01:53 PM)JBlock Wrote:  by same you mean the same amount of letters or the exact same word?

Exact same word. But lower/caps doesn't matter. So DOG is still equal to dog :)
was coded in python 3.5, so its input instead of raw_input
🤝
Code
word1 = input("first word")
word2= input("second word")


def checkyourselfbeforeyouwreckyourself(word1,word2):
    count1=0
    count2=0
    if(word1 == word2):
        return("same")
    else:
        for x in word1:
            if(x =="e"):
               count1+=1
        for x in word2:
            if(x =="e"):
               count2+=1

    if(count1>count2):
         return(word1)
    elif(count2>count1):
        return(word2)
    else:
        return("both words had the same amount of the letter \"e\"")

var=checkyourselfbeforeyouwreckyourself(word1,word2)
print(var)
(Feb 22, 2016 02:08 PM)JBlock Wrote:  was coded in python 3.5, so its input instead of raw_input
🤝
Code
word1 = input("first word")
word2= input("second word")


def checkyourselfbeforeyouwreckyourself(word1,word2):
    count1=0
    count2=0
    if(word1 == word2):
        return("same")
    else:
        for x in word1:
            if(x =="e"):
               count1+=1
        for x in word2:
            if(x =="e"):
               count2+=1

    if(count1>count2):
         return(word1)
    elif(count2>count1):
        return(word2)
    else:
        return("both words had the same amount of the letter \"e\"")

var=checkyourselfbeforeyouwreckyourself(word1,word2)
print(var)

Thanks!

for x in word1:
if(x =="e"):
count1+=1
for x in word2:
if(x =="e"):
count2+=1

So whenever there's an "e" in the word it adds +1 to the count1 variable right? :)
It's actually pretty simple now when I see the solution :)
Also what's the difference between python 3.5 and 2.7? I'm pretty sure we use 2.7 in our class.
whenever there is an "e" in the word1 it adds +1 to count1
whenever there is an "e" in the word2 it adds +1 to count2


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by Too FarJul 14, 2022 09:00 AM 2 159 Jul 14, 2022 09:00 AM
Last Post: Too Far
[Python] by blackcoder00Mar 6, 2019 08:33 AM 7 508 Mar 6, 2019 08:33 AM
Last Post: datguy.dev