Posts

Showing posts from January, 2018

Assignment 3

Coding from datetime import datetime """CONFIG""" # maximum number of pizzas in one order number_of_order = 3 # delivery charge (in $) delivery_charge = 3.00 # list of dictionaries (pizzas) with name and price pizza_available = ( { "name" : "Tuna Pizza" , "price" : 15.00 } , { "name" : "Cheese Pizza" , "price" : 15.00 } , { "name" : "Pepperoni Pizza" , "price" : 16.00 } , { "name" : "Honey Garlic Chicken Pizza" , "price" : 17.00 } , { "name" : "Vegetarian Pizza" , "price" : 17.00 } , { "name" : "Supreme Pizza" , "price" : 18.00 } ) # class with default order details class Order(): def __init__ ( self ): self .pickup = True self .name = "" self .address = None self .phone = None self .number_pizza...

Validation with write and date and time

Image
Output Coding 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:" + str (age) + " \n " ) file.write( "Address:" + address + " \n " ) file.write( "Date and Time:" + str (date) + " \n " ) file.close() def view (): view = open ( "file.txt" , "r" ) print (view.read()) view.close() validcharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " while True : name = input ( "Enter your name:" ) if all (char in validcharacters 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" ) def input_number (message): while True : ...

Data Validation

Image
Code # Name: Muhamad Raziq Aiman bin Haji Rosman # Version: Python 3 # Date: 24 January 2018 validcharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " while True : var1 = input ( "Enter your name:" ) if all (char in validcharacters for char in var1): print ( "Your name is " + var1) break print ( "That's invalid, please try again. Please enter characters A-Z and space only" ) def input_number (message): while True : try : userInput = int ( input (message)) except ValueError : print ( "Not an integer! Try again." ) continue else : return userInput break age = input_number( "How old are you?" ) print ( "You are " + str (age) + " years old" ) Output