Posts

validation write and date time

from datetime import datetime def insertintofile (name , age , address): date = datetime.now() file= open ( "file.txt" , "w" ) file.write( "name:" + name + " \n " ) file.write( "age:" + age + " \n " ) file.write( "address:" + address + " \n " ) file.write( "date and time :" + str (date) + " \n " ) file.close def view (): file= open ( "file.txt" , "r" ) print (file.read()) file.close() valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " while True : name = input ( "enter your name " ) if all (char in valid_characters for char in name): print ( "your name is:" + name) break print ( "That's invalid, please try again. Please enter characters A-Z and space only" ) valid_characters = "1234567890" while True : age = input ( ...

data validation

how to do validation on python  code  # khairah, version python3, 24 Jannuary 2018 valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " while True : name = input ( "Enter Your Name" ) if all (char in valid_characters for char in name): print ( "your name is:" + name) break print ( "That's invalid, please try again. Please enter characters A-Z and space only" ) # validating numbers def input_age (message): while True : try : userInput= int ( input (message)) except ValueError : print ( "not an integer! Try again." ) continue else : return userInput break age= input_age( "How old are you?" ) print ( "you are" + str (age) + "years old" ) output Enter Your Name khairah your name is: khairah How old are you? 12 you are12years old Process finished with exit code 0 ...

program Specification

Image
definition - define of what computer program expect to do should have; input, process and output flowchart (keyword)   input - enter, input   process - view, calculate, formula   output - show, display Outing Variables - identify what variable you are using create a program that would add 2 number input                        Process                                                      Output   num1                        sum= num1 + num2                                  sum  num2 Outing variables variable name                      ...

control structure for for loop

# Program to find the sum of all numbers stored in a list # List of numbers numbers = [6, 5, 3] # variable to store the sum sum = 0 # iterate over the list for val in numbers: sum = sum+val # Output: The sum is 48 print("The sum is", sum)

identity operator

Image
#identity operator a= 20 b= 20 print ("line1", "a=", a, " : ", id(a), "b=", b, ":", id(b)) if (a is b): print("line 2 - a and b have same identity") else: print ("line 2 - a and b do not have same identity") if (id(a) == id(b)): print ("line 3 - a and b have same identitiy") else: print ("line 3 - a and b do not have same identity") b= 30 print ("line 4", "a=", a, ":", id(a), "b=", b, ":", id(b)) if (a is not b): print("line 5 - a and b do not have same identity") else: print("line 5 - a and b have same identity")

membership operators

Image
#membership operator a = 10 b = 20 list1 = [1, 2, 3, 4, 5] fi ( a in list1) : print ("line 1 - a is availabe in the givent list") else: print ("line 1 -  a is not available in the given list") if ( b not in list1): print ("line 2 -  b is not availabe in the givent list") else: print ("line 2 - b is available in the given list") c= b/a if (c in list 1) : print ("line 3 - b is availabe in the givent list") else: print ("line 3 -  b is not available in the given list #membership operator  a = 10  b = 20  list1 = [1, 2, 3, 4, 5] if ( a in list1) : print ("line 1 - a is availabe in the givent list")  else: print ("line 1 -  a is not availabe in the givent list") if ( b not in list1) :   print ("line 2 -  b is not availabe in the givent list") else: print ("line 2 - b is availabe in the givent list")  c= b/a if (c in list1) :   ...

logic operation

Image
syntax error example else to else: