python - 我正在尝试用 spyder python 编写这个程序(很长一段时间后开始)。基本上我希望数据框“信息”永久存储用户值
问题描述
这是该项目的代码。它基于一个银行管理系统,可以注册新用户并允许注册用户进行交互。该代码非常基本,尚未完成,即仅编码到您可以注册的部分。它接受用户输入并将它们存储在数据框“信息”中。问题是每当我执行代码时,之前输入的用户值就会消失。
- - 编码:utf-8 - -
"""
Created on Mon Sep 13 19:45:40 2021
@author: Hp
"""
import pandas as pd
import datetime as dt
import sys
print("Welcome to Lotus Bank! Please select from one of the options below: ")
print("1. Create a new user account")
print("2. Login into an existing bank account.")
in1 = int(input())
#create bank account
if in1 == 1:
print("We are honoured that you chose us as your trusted bank. Please fill in all the information to apply for a bank account.")
pf = input("Prefix: ")
n1 = input("First Name: ")
n2 = input("Last Name: ")
name = pf + " " + n1 + " " + n2
print("Date of Birth: ")
d1 = int(input("Day: "))
if d1 >= 1 and d1 <= 31:
d2 = int(input("Month: "))
else:
print("Please enter a valid day.")
sys.exit()
if d2 >= 1 and d2 <= 12:
d3 = int(input("Year: "))
else:
print("Please enter a valid month.")
sys.exit()
if d3 >= 2004:
print("Age too less to open a bank account.")
sys.exit()
elif d3 <= 1920:
print("Please enter a valid year.")
sys.exit()
else:
g = input("Please enter your gender: ")
print(" ")
age = 2021-d3
dob = dt.date(d3, d2, d1)
print("Date of Birth: ", dob)
print("Full Name: ", name)
print("Gender: ", g)
print("Age: ", age)
print(" ")
c1 = input("Is this information correct? [Y/N] ")
if c1 == 'Y' or 'y':
print("Please continue: ")
elif c1 == 'N' or 'n':
("Please retry entering your details.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
print("Please select a number to choose the type of account to be created: ")
print("1. Current Account")
print("2. Savings Account")
c2 = int(input())
if c2 == 1:
print("You have chosen Current Account. Please fill the following details to continue: ")
acnt = "Current"
sal = int(input("Please enter your monthly salary: "))
if sal < 30000:
print("Salary too low to open a Current Account. Please try to open a Savings Account.")
sys.exit()
else:
dep = int(input("Enter Deposit value (minimum deposit value is 50000): "))
if dep < 50000:
print("Deposit value is too low. Please try again.")
sys.exit()
else:
c3 = input("You have deposited "+ str(dep)+ ". Please confirm[Y/N] ")
if c3 == 'Y' or c3 == 'y':
print("Thank you for creating your bank account with us.")
pin = int(input("Please enter your desired pin: "))
c4 = input("Please confirm your pin: "+ str(pin)+ " [Y/N] ")
print(" ")
if c4 == 'Y' or c4 == 'y':
ipm = 0
print("Please confirm the information provided: ")
print("Account Type: ", acnt)
print("Salary: ", sal)
print("Deposit: ", dep)
print("PIN: ", pin)
c5 = input("[Y/N] ")
if c5 == 'Y' or c5 == 'y':
info = pd.DataFrame([[name, dob, age, g, acnt, sal, dep, ipm, pin]], columns = ["Name", "Date of Birth", "Age", "Gender", "Account Type", "Salary", "Deposit", "Interest", "PIN"])
print("You have successfully created your bank account! Please login to continue.")
sys.exit()
elif c5 == 'N' or c5 == 'n':
print("Please retry creating your bank account.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
elif c4 == 'N' or c4 == 'n':
print("Please try to create your bank account again.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
elif c3 == 'N' or c3 == 'n':
print("Please retry creating your bank account.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
elif c2 == 2:
print("You have chosen Savings Account. Please fill in all the information to apply for a bank account.")
acnt = "Savings"
sal = int(input("Please enter your monthly salary: "))
dep = int(input("Please enter deposit amount: "))
print(" ")
ipm = 0.06*dep
print("Your interest p.a. is: " + str(ipm))
print(" ")
print("Please confirm the information provided: ")
print("Account Type: ", acnt)
print("Salary: ", sal)
print("Deposit: ", dep)
c6 = input("[Y/N]: ")
if c6 == 'Y' or c6 == 'y':
pin = int(input("Please enter your desired pin: "))
c7 = input("Please confirm your pin: "+ str(pin)+ " [Y/N] ")
if c7 == 'Y' or c7 == 'y':
info = pd.DataFrame([[name, dob, age, g, acnt, sal, dep, ipm, pin]], columns = ["Name", "Date of Birth", "Age", "Gender", "Account Type", "Salary", "Deposit", "Interest", "PIN"])
print("You have successfully created your bank account! Please login to continue.")
sys.exit()
elif c7 =='N' or c7 == 'n':
print("Please retry creating your bank account.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
elif c6 == 'N' or c6 == 'n':
print("Please retry creating your bank account.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
else:
print("Please enter a valid option.")
sys.exit()
请建议如何永久存储用户值,以便即使在执行代码后我也可以访问数据。非常感谢所有建议。谢谢!
解决方案
推荐阅读
- python - Pandas DataFrame:根据多个条件填充 NaN 值
- vue.js - 如何在 vuetify 中初始化插槽的变量
- django - 每次运行代码时我都会收到以下错误,但我不知道出了什么问题
- python - 数字之间的区别。实数和浮点数
- javascript - 如何为此表的单元格创建工作标识符?
- azure - Azure 数据工厂存储变量到 blob 中的文件
- java - 将 Apache Cassandra 与基于 Java 11 的 Java 应用程序一起使用?
- angular - 从一个 Angular 9 项目创建多个应用程序
- javascript - 无法 POST 成功的 ajax 请求
- mysql - 使用聚合函数 mySQL 时不断出现错误