Computers and Technology, 10.02.2020 03:56, maddy6882
Exercise 9.2.9: Strings To Integers5 points
Make a function called safe_int that takes a single argument. This function should try to convert the argument into an integer. If this succeeds, the function should return that integer. Otherwise, the function should return 0.
Then, use this function in a list comprehension to create a list out of the given list. The new list should contain either a 0 or the correct integer in place of every string in the given list:
[0, 2, 7, 0]
Make sure to print out the resulting list.
This is my code so far(i dont know what's wrong with it):
list_of_strings = ["a", "2", "7", "zebra"]
# Your code here...
def safe_int():
list = [int(x) if x. isdigit() else 0 for x in list_of_strings]
print list
safe_int()
but its asking "Function "safe_int" should take exactly 1 argument" and "You should use safe_int in a list comprehension", i dont know how to fix this code please help
Answers: 3
Computers and Technology, 22.06.2019 20:40, wutdmgamerz
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
Computers and Technology, 24.06.2019 06:30, meganwintergirl
Ineed to know the anwser to all these questions
Answers: 2
Computers and Technology, 24.06.2019 19:30, hermine40
Which phrase is the best definition of a pivottable a a table containing data that is organized horizontally b a table used to calculate financial pivot values c a tool used to summarize data d a table containing specific formatting
Answers: 1
Computers and Technology, 25.06.2019 04:30, precioussmith76
What should be used when performing vehicle maneuvers?
Answers: 1
Exercise 9.2.9: Strings To Integers5 points
Make a function called safe_int that takes a singl...
Make a function called safe_int that takes a singl...
Mathematics, 07.07.2019 21:30
Mathematics, 07.07.2019 21:30
Mathematics, 07.07.2019 21:30
Mathematics, 07.07.2019 21:30