Jump to content

What am I missing? - Python - 2

Next question.

 

This is my current coding :

dial=input('Dial a number: ')
dial2=dial.split()
number=[]
for i in dial2:
  if len(i)>10:
    number.append(((len(i))))
  elif len(i)==10:
    i=''
    number.append(str(len(i)))
print(''.join(number))
 
 
It needs to do this: What's missing?

Write a program to convert from a series of pulses to a phone number. For this question the pulses will be represented as Xand different digits will be separated by spaces. For example:

 
 
 
 
Dial a number: XXX XX XXXXX
325
 

Here is another example:

 
 
 
 
 
Dial a number: XXXXXX XXX XXXXXX XXXXX XXXXX XXXXX XXX XX XX XXXXXX
6365553226
 

Here is another example:

 
 
 
 
 
Dial a number: XXXXX XXXXX XXXXX XX XXX XXXXXX XXXXXXXX
5552368

 

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to comment
https://linustechtips.com/topic/210410-what-am-i-missing-python-2/
Share on other sites

Link to post
Share on other sites

i can only help you in c++, what i would do is either wright a bunch of if statements accounting for the 1-9. or i would wright a array and test it that way

CPU: i7 4770k@4.3Ghz GPU: GTX 780ti Motherboard: ROG maximus vi formula PSU: Evga supernova 1000w Platinum

Case: NZXT Switch 810 Memory: g.skill ripjaws X Cooler: Corsair h100i(getting custom loop when i get money next) Storage: Samsung 840 evo 250gb Keyboard: Corsair K95 Mouse: SteelSeries Rival

Link to post
Share on other sites

and for this one I got:

dialed = raw_input("Dial a number: ").lower().split(' ')number = ""for item in dialed:    number += str(item.count('x'))print number

Can I ask where are you getting these problems from?

Also you can reuse variables so you don't have to go dial1, dial2, dial3 so on.

Thank you!

To answer your question, it's from : http://www.codecademy.com/

Lastly, I'm getting an error: When inputting XXXXXXXXXX XXXX X XXX XXXX XXXXXX XXX XX XXX XXXX 

It outputs this: 10413463234

Instead of 0413463234

|CPU: Intel 5960X|MOBO:Rampage V Extreme|GPU:EVGA 980Ti SC 2 - Way SLI|RAM:G-Skill 32GB|CASE:900D|PSU:CorsairAX1200i|DISPLAY :Dell U2412M X3|SSD Intel 750 400GB, 2X Samsung 850 Pro|

Peripherals : | MOUSE : Logitech G602 | KEYBOARD: K70 RGB (Cherry MX Brown) | NAS: Synology DS1515+  - WD RED 3TB X 5|ROUTER: AC68U

Sound : | HEADPHONES: Sennheiser HD800 SPEAKERS: B&W CM9 (Front floorstanding) ,  B&W CM Center 2 (Centre) | AV RECEIVER : Denon 3806 | MY X99 BUILD LOG!

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×