Intro to Programming and Logic: Python 2, Chapter 8 – Strings
(so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration)
Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value.
Your function should return True in any of these cases: 0.17, .17, 5.27, 6, 7
It should return False in any of these cases: aX, a.4, 4*5, 45.123.345
Write a program that will test this function. It will ask the user for a float. It will then feed that input into the function that was written for this program. It will then print out an appropriate message.
You should have 2 functions – one function called isfloat() and the other is main().
Grading:
Program compiles with no syntax errors: 12 points
Program does what it is supposed to do: 5 points
BONUS: make it also return True for negative floats: 2 points
You have meaningful comments: 3 points
-multi-line comments at top to describe what the program does
-comments that describe what your functions do -comments in your program wherever else would be useful to the reader of your code
Hello, here is the completed code you wanted. Every important statement is explained using comments. Please check and let me know if you have any doubts. Thanks.
I have also attached screen shot of the code also. If any compilation error related to Code indentation occurs please compare and correct the code with screen shot.
CODE
#isfloat function
def isfloat(string):
"""
The function to analyze the string whether
it is a valid float value or not
Arguments:
string = input string from user
Returns:
True = if input string is a valid float
value
False = if input string is not a valid float
value
"""
#try block
try:
#try converting input string into
float
#if string converts into
float
#return True
float(string)
return True
#except block
except ValueError:
#if string is not a valid
float
#if it can't convert into float
which will raise a ValueError
#returns False
return False
#main function
def main():
"""
The function to test isfloat function
Called Functions:
isfloat() = analyze the string whether
it is a valid float value or not.
Variables:
string = to input string from user
"""
#prompt for float value as string
string = raw_input("Enter a float value: ")
#if isfloat returns True
if isfloat(string):
#prints message
print(string+" is a valid
float")
#if isfloat returns False
else:
#prints message
print(string+" is not a valid
float")
#calling main function
if __name__ == "__main__":
main()
OUTPUT
CODE SCREEN SHOT
Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the...
Write the following functions, as defined by the given IPO comments. Remember to include the IPO comments in your submission. Be sure to test your code -- you can use the examples given for each function, but you should probably test additional examples as well -- and then comment-out or remove your testing code from your submission!. We will be testing your functions using a separate program, and if your own testing code runs when we load your file it...
Programming Assignment #2 EE 2372 MAKE SURE TO FOLLOW INSTRUCTIONS CAREFULLY, IF YOU HAVE ANY DOUBTS PLEASE EMAIL ME! This programming assignment will just be a small extension to programming assignment 1. In the first assignment each of the functions could only take a predefined number of inputs. This time the objective is to be able to complete these functions with any amount of inputs. The user will pass arguments through the command line (this means you will have to...
I really need help with this python programming assignment Program Requirements For part 2, i need the following functions • get floats(): It take a single integer argument and returns a list of floats. where it was something like this def get_floats(n): lst = [] for i in range(1,n+1): val = float(input('Enter float '+str(i)+': ')) lst.append(val) return lst • summer(): This non-void function takes a single list argument, and returns the sum of the list. However, it does not use...
PHP Programming Question. Use the techniques you learned so far to create an Address Book application that stores names, e-mail addresses, and phone numbers in a text file. Validate all input fields and include functionality that allows the user to view the address book. Also, include code that sorts the address book by name and deletes duplicate entries. Each page in the application should have a link back to the main page. Be creative and add extra features if you...
Python Programming Chapter 5 Programming Exercise Dinner Selection Program (60 points total) Pseudocode (10 points) As the family cook, you know that the toughest question of the day is "What's for dinner?" You For decide to write a program to help you do days of meal planning for the entree, side and dessert. You will need to use random numbers and functions to complete the project. What's Dinner? • • • Start with a pseudocode (10 points). Write the pseudocode...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...
Have the function wildcard(str) read str which will contain two strings separated by a space.The first string will consist of the following sets of characters: +, *, $ and {N} which is optional.The plus (+) character represents a single alphabetic character, the ($) character represents anumber between 1-9, and asterisk (*) represents a sequence of the same character of length 3unless it is followed by {N} which represents how many characters would appear in thesequence where N will be at...
QUESTION 21 while True: , in Python, can be used to create an infinite loop. True False 2 points QUESTION 22 The Python Framework does inform you where an error occurred True False 2 points QUESTION 23 ____ is a critical component to being able to store data and information long term. File Access Memory Print function with 2 points QUESTION 24 Error handling is also known as ___ handling Result Recursion Exception Crash 2 points ...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...