Постови

Приказују се постови за јануар, 2020

Python verbose function

Write a function called verbose that, given an integer less than 100000, returns the name of the integer in English. As an example, verbose(123456) should return one hundred twenty-three thousand, four hundred fifty-six. def verbose(n):     d = { 1 : 'one' , 0 : '' , 2 : 'two' , 3 : 'three' , 4 : 'four' , 5 : 'five' , 6 : 'six' , 7 : 'seven' , 8 : 'eight' , 9 : 'nine' ,  10 : 'ten' , 11 : 'eleven' , 12 : 'twelve' , 13 : 'thirteen' , 14 : 'fourteen' , 15 : 'fifteen' , 16 : 'sixteen' , 17 : 'seventeen' ,  18 : 'eighteen' , 19 : 'nineteen' , 20 : 'twenty' , 30 : 'thirty' , 40 : 'forty' , 50 : 'fifty' , 60 : 'sixty' , 70 : 'seventy' , 80 : 'eighty' , 90 : 'ninety' }     if n < 100000 :         t = str (n)         if len (t) == 1 :              print (d[ in...

Python cheating at the game Scrabble

Write a program to cheat at the game Scrabble. The user enters a string. Your program should return a list of all the words that can be created from those seven letters. wordlist = [line.strip() for line in open ( 'C:/Users/ZM/Desktop/Documents/New folder/wordlist.txt' )] user_word = input ( 'Enter word: ' ) d = {} d1 = {} c = 0 for i in user_word:     if i in d1:         d1[i] += 1     else :         d1[i] = 1 print (user_word) for i in wordlist:     for j in i:         if j in d:             d[j] += 1         else :             d[j] = 1     if d == d1:         print (i)     d = {} SOLUTION:   ...

Python game Jotto

This problem is about a version of the game Jotto. The computer chooses a random five-letter word with no repeat letters. The player gets several turns to try to guess the computer’s word. On each turn, the player guesses a five-letter word and is told the number of letters that their guess has in common with the computer’s word. from random import choice enter_lenght = eval ( input ( 'Enter number of letters: ' )) wordlist = [line.strip() for line in open ( 'C:/Users/ZM/Desktop/Documents/New folder/wordlist.txt' )] word = '' K = [] for i in wordlist:     if len (i) == enter_lenght:         K.append(i) word = choice(K) d = {} d1 = {} c = 0 for i in word:     if i in d1:         d1[i] += 1     else :         d1[i] = 1 print (word) t = 0 while t <= enter_lenght:     user_word = input ( 'Enter ...

Python read from text file VII find percentage letters in words

Слика
Using the wordlist, produce a dictionary whose keys are the letters a through z and whose values are the percentage of words that use that letter. wordlist = [line.strip() for line in open ( 'C:/Users/ZM/Desktop/Documents/New folder/wordlist.txt' )] L = [] for i in wordlist:     i= i.lower()     L.append(i) d = {} for i in L:     for w in i:         if w.isalpha():              if w in d:                 d[w] += 0              else :                   d[w] = 0 D = list (d) count = 0 for i in range ( len (D)):     for s in range ( len (L)):       ...

Python read from text file VI anagram

Слика
Ask the user to enter several letters. Then find all the words that can be made with those letters, repeats allowed. wordlist = [line.strip() for line in open ( 'C:/Users/ZM/Desktop/Documents/New folder/wordlist.txt' )] print (wordlist) enter_num_let = eval ( input ( 'Enter number of letters: ' )) i = 0 L = [] word = '' counter = 0 while i <= enter_num_let- 1 :     letters = input ( 'Enter letter: ' )     L.append(letters)     word = '' .join(L)     i += 1 for i in range ( len (wordlist)):     for j in range ( len (wordlist[i])):          if len (wordlist[i]) == len (word):             if L[j] not in wordlist[i]:                 break          ...