-1

Hey all,

So basically I need to change the code so that the phonebook and the inverse phonebook are easily updated and maintained. Also, whenever I add an entry, both phonebooks need to be updated.

Lastly, when I write a phonebook to a file, write a backwards phonebook as well.
Do your best to handle cases when two individuals share a phone number. If both Fido and Lucky have the same phone number (212-888-3434). One of them will not be in the backwards phonebook unless, the backwards phonebook is modified.
Suggestion: for the backwards phonebook, allow the values to be a list of names, rather than a single name. Alternatively, use a string that includes all of the barers of a phone number. Thus, in the above example, the value for '212-888-3434' could be 'Fido and Lucky' or ['Fido','Lucky'].

Help would be GREATLY appreciated!

[CODE]import os
telephone_book = {}
inverse_phonebook = {}

def add_number_to_phone_book(key,value):
telephone_book[key] = value

def add_line_to_phone_book(line):
words = line.split()
name = ''
if len(words) >= 2:
for word in words[:-1]:
name = name+' '+word
name = name[1:]
add_number_to_phone_book(name,words[-1])
else:
print('Warning null entry')

def add_phone_numbers_from_file(file):
new_numbers = open(file, 'r')
for line in new_numbers:
add_line_to_phone_book(line)
new_numbers.close()

def write_phone_numbers_to_file(file):
write = open(file,'w')
for key in telephone_book:
write.write(key+' '+ telephone_book[key]+os.linesep)
write.close()

def create_inverse_phone_book(dictionary):
inverse_phonebook.clear()
for key in dictionary:
inverse_phonebook[dictionary[key]] = key

def create_inverse_phone_book2(dictionary):
inverse_phonebook.clear()
for key in dictionary:
if telephone_book[key] in inverse_phonebook:
inverse_phonebook[dictionary[key]] = \
inverse_phonebook[dictionary[key]]\

  • ' and ' + key
    else:
    inverse_phonebook[dictionary[key]] = key

def create_inverse_phone_book3(dictionary):

This is ...

0

I can't get this to generate random shapes, etc. Basically what I need to do is randomly generate similar lists consisting of:
combinations of 'square', 'triangle', 'circle' and 'left'.
And random numbers from 1 to 10 for physical dimensions and 10 to 90 for angles
Have the program use 'split' to divide the numbers from the commands so that the turtles can have more variety in their random creations.

Any help would be greatly appreciated, I think I've reached a roadblock :p

[CODE]import turtle
import random
import math
import time
my_screen = turtle.Screen()
my_turtle = turtle.Turtle()
turtle_commands = ['square 20','circle 20','triangle 20', \
'left 15 40','left 70 40',\
'left 90 40', 'straight 50']
number = int(input('Input a random positive number: '))

def get_random_turtle_commands(number):
new_list = []
i = 0

for i in number:

while(i < number):
    i=i+1
    index=math.ceil(random.random()*len(turtle_commands)-1)
    new_list=index.append(turtle_commands[index])
return(new_list)

def draw_square(side):
for number in range(4):
turtle.fd(side)
turtle.left(90)

def draw_triangle(side):
for number in range(3):
turtle.fd(side)
turtle.left(60)

def draw_movement(degree,length):
turtle.left(degree)
turtle.fd(length)

def turtle_command(string):
turtle.pd()
if string == 'square 20':
draw_square(20)
elif string == 'circle 20':
turtle.circle(20)
elif string == 'triangle 20':
draw_triangle(20)
elif string == 'left 15 40':
draw_movement(15, 40)
elif string == 'left 70 40':
draw_movement(70,40)
elif string == 'left 90 40':
draw_movement(90,40)
elif string == 'straight 50':
turtle.fd(50)
turtle.pu()

def final_output():
for x in string:
turtle_command(string)

def main():
get_random_turtle_commands(number)
final_output()

main()

[/CODE]

0

So I have the y and e endings down, just need some help with the middle. Basically, I need to double the last letter before adding er if:
the last letter is b,d,g,l,m,n,p,r,s or t
and the second to last letter is not the same as the last letter.

[CODE]def add(word):
wordlength = len(word)-1
if word[wordlength]=="y":
word=word.replace('y', 'i')
word=word +'er'
print(word)
elif word[wordlength] == "e":
word=word+'r'
elif word[wordlength] == [[/CODE]

Should I create a list of consonants and re.search through it?

Some help would be greatly appreciated!

0

[CODE]
def turn_words_into_numbers(number_list):
output = 0
current = 0
for index in range(len(number_list)):
current = eval(number_list[index])
if(output==0):
output=output+current
elif(output < current):
output=output*current
elif(output>current):
output=output+current
else:
return('error')
print('index:',index,'output:',output,'current:',current)
return(output)

def convert_string_to_lower_case(number_list):
new_string = ''
for i in number_list:
if 65 <= ord(i) <= 90:
new_string=new_string+convert_character_to_lower_case(i)
else:
new_string=new_string+i
return(new_string)

def tokenize_string(new_string):
print(new_string.split())

def main():
number_list = input('Enter a written number: ')
convert_string_to_lower_case(number_list)
tokenize_string(number_list)
turn_words_into_numbers(number_list)
main()[/CODE]

My new code, though there are errors. Thanks for the help so far guys! It doesn't work still, but I hope I'm on the right track...any more suggestions?

0

Write parts 1 (convert string to lowercase) and 2 (tokenize string) of that code and incorporate the function below. Use the string.split function. Get the code to work as a cohesive unit to convert strings like "two hundred sixty two" to numbers like 262.

This is basically what I need to do.

[CODE]def turn_words_into_numbers(number_list):
output = 0
current = 0
for index in range(len(number_list)):
current = eval(number_list[index])
if(output==0):
output=output+current
elif(output < current):
output=output*current
elif(output>current):
output=output+current
else:
return('error')
print('index:',index,'output:',output,'current:',current)
return(output)[/CODE]

The code is not really correct, so any help would be greatly appreciated, I have NO idea what to do.

0

def timer_tenth_second():
import time
hh = 0
mm = 0
ss = 0
ff = 0
counter=ff
while True:
counter+= 1
if counter > 9:
counter = 0
if counter < 1:
ss= ss + 1
if ss > 59:
print(hh, + ":", + mm, + ":", + ss, + ":", + str(ff))
time.sleep(.1)
timer_tenth_second()

Here is my current code, help ?

0

For a project i'm working on now, i need to create a function that is in the format Hours:Minutes: seconds: Fraction

where fraction is 1/10th of a second.

It should print out every one tenth of a second. I have no idea where to start or how to do this, and am fairly new to python.

it has to be as simple as possible and use time and time.sleep. I know time.sleep has to be time.sleep(.1), and to import time, but I dont know how to use nested loops with this.

Some help would be greatly appreciated :)