Hack Forums
[Python] python (easy task help) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] python (easy task help) (/showthread.php?tid=5180343)



python (easy task help) - Gameh3x - Feb 22, 2016

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?


* - JBlock - Feb 22, 2016

by same you mean the same amount of letters or the exact same word?


* - Gameh3x - Feb 22, 2016

(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 :)


* - JBlock - Feb 22, 2016

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)



* - Gameh3x - Feb 22, 2016

(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.


* - khalouni - Feb 22, 2016

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