#average word count def main(): sentence = input('Please enter a sentence: ') words=sentence.split() sum=0 for word in words: sum += len(word) average = sum / len(words) average=round(average,0) print (' the sentence has', len(words), 'words') print ('the average word length is', average) main()
#using ifs def main(): temp = float(input('Enter a temperature: ')) #equality needs == if temp==100: print('Jackpot') #actually from chapter 7 if temp >= 90: print ("It is hot") elif temp >= 80: print ("it's warm") elif temp >= 70: print ("it's comfortable") else: print("it's cold") main()
No comments:
Post a Comment