Başa dönebilmek için bir "while" döngüsüne yerleştirmem gerektiğini biliyorum. Ancak, kullanıcı gerektiğinden daha fazla karakter girdiyse, yeniden başlatmak için bir süre döngüm var. Bu durumu değiştirmeli miyim? ya da bir fonksiyon eklemeden bunu düzeltmek mümkün mü?Döngünümün yeniden başlatılmamasının neden anlama geldiğini anlama
net olmadığı için benim hatam -edit-: İşte benim gerçek kod var
abb_dict = {
'lol': 'laughing out loud',
'bfn': 'bye for now',
'cuz': 'because',
'omw': 'on my way',
'tbh':'to be honest',
'afk':'away from keyboard',
'brb':'be right back',
'afaik':'as far as i know',
'np':'no problem',
'rofl':'rolling on floor laughing',
'asap': 'as soon as possible',
}
for k, v in abb_dict.items(): # list all the abbreviations available to be translated
print k, v
tweet_str = raw_input('Enter the sentence with an abbreviation in it :\n').lower()
while len(tweet_str) > 160: ## if tweet_str passes 160 characters it will display a message
print "Too long, keep it less than 160 characters"
tweet_str= raw_input('Enter the sentence with an abbreviation in it :\n').lower()# prompts user to re-enter new string
for k in abb_dict: # looks for any key variable in dictionary
if k in tweet_str: # if the key is seen in the user input
print k, abb_dict[k] # prints key variable along with dictionaries value which is the definition of the abbreviation
for key, value in abb_dict.iteritems():
tweet_str = tweet_str.replace(key, value) #replaces abbreviations with their definition
print tweet_str
gerçek kodunuz veya sahte kod mı? – wnnmaw
Anında yanıt, '> 100',' 100'den büyük ',' 0'dan küçük olmamak 'anlamına gelir, – roganjosh
Ayrıca, girinti. 'For' döngüsü ve takip eden her şeyin 'while' döngüsünde olması gerekiyorsa, bu bir problem değildir. – jpmc26