联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-06-05 04:12


Files to submit: words.py

Time it took Matthew to Complete: 10 mins

Requirements

● Submit only the files requested

● Print all real numbers to 2 decimal points unless stated otherwise

Restrictions

● No global variables may be used

● The only code that may appear outside of a function are function definitions and function

calls

● NEW: You may not import any modules

Description

Write a program called words.py that when provided with a dictionary and a list of characters prints

all possible words that can be formed using those characters.

Problem Details

● Your program will be provided a file that contains all of the known words with one word per

line

○ All of the words in the file are lowercase

● Your program will be provided with a list of letters

○ The letters will all be on one line with a space between each letter

● Your program should output all possible words that be formed using those letters

○ These words should be displayed in alphabetical order

○ No duplicates should be displayed

○ Each letter can only be used a single time

■ For example if the user inputs a and p then the word app can NOT be formed

as it uses the same letter, p, twice.

■ If the user inputs a p p then the word app could be formed as you use each p

once

Input

● All input will be valid

● The name of the file containing all of the words

● The letters being used

○ All on one line with a space between each letter

Hints

● You'll want to use a set to hold the words from the file.

○ Sets model the mathematical concept of a set: a collection of unique things

○ Sets have very fast lookups (using the in keyword)

○ The methods on sets you'll probably need are

■ set.add(element)

■ Add element to the the set

■ element in set

■ Check if element is in set

Examples

User input has underlined to help you differentiate what is user input and what is program output.

You do not need to underline anything.

Example 1

Enter the name of the file containing all of the words: english.txt

Please enter your letters separated by a space: c a t b

a

ab

abc

abt

ac

act

at

bat

ca

cab

cat

ct

tab

Example 2

Enter the name of the file containing all of the words: english.txt

Please enter your letters separated by a space: u u b t c s

bus

bust

but

buts

cs

cst

ct

cts

cub

cubs

cut

cuts

sc

scut

st

stub

sub

tbs

tub

tubs

us

ut


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp