Python Forum
Trouble with general code flow
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with general code flow
#1
As you can see by my crude coding I am a newbie.  I've gotten this far and know my objectives could be achieved by much better coding (last file asked to be open fails).  The objective is to put together a program based on a book about Christian counseling principles where-by through series of questions and answers received an analysis is achieved.  I had planned upon getting the question and answer part put together to go back inserting code to capture response and based on such response insert data into a client file in order to form the final analysis.
Can anyone offer help as to better code and ideas to achieve my final goal.  Thank-you
redacted


#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
"""
Created on Fri May 19 23:55:18 2017

@author: nisbet
"""

#def main():
#    Info.txt = raw_input("Info.txt: ")
#    infile = open(Info.txt, 'r')
#    data = infile.read()
#    print ("data")
#next
...
...
name = input('What is your name? ')
print('Hello ' + name)

Age = input('What is your age? ')
print('Your age is ' + Age)

num = input('Give me a PH number? ')
print('Is this right: ' + str(num))
import time
time.sleep(10)
with open("/home/nisbet/Heart_of_Man/Info.txt", "rt") as in_file:
   Info = in_file.read()

print(Info)
import time
time.sleep(15)
import sys
import os
with open("/home/nisbet/Heart_of_Man/forword.txt", "rt") as in_file:
   forword = in_file.read()
print(forword)
next
eval(input('Enter question number 1 through 10:'))
with open("/home/nisbet/Heart_of_Man/Question1.txt", "rt") as in_file:
       Question1 = in_file.read()
       if input == 1:
           Question1 = 1      
print(Question1)
import time
time.sleep(60)
next
eval(input('Does A B or C best discribe '))
print(name)
with open("/home/nisbet/Heart_of_Man/QuestionA.txt", "rt") as in_file:
       QuestionA = in_file.read()
       if input == A:
           QuestionA = A      
print(QuestionA)
Reply
#2
Let's start with it's never a good idea to provide any personal information about yourself, including your email, on a public forum. This is a public forum, the questions and answers are for the benefit of all. Sending you an answer via email defeats the purpose of the forum.

As to your code, you only need to import your modules once and unless you have a really good reason, they should go at the top after line 7 and before line 9. "..." on line 15 and 16 serves no purpose. There is no "next" (lines 18 and 47) in Python. Since "num" is already a string (line 23) there really no need to hammer home the point in line 24, just print num. I'm not sure why you are using "eval" (lines 39 and 48), it you are expecting an integer, then use question_number = int(input("Enter a number ")) if you are expecting a letter, just use letter = input("Enter a letter ") .

These are a few of the problems. Tidy them up and come back should you have other problems. And read the Python 3.4 Documentation
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Alicat Flow Meter data acquisition marenr 0 351 Sep-29-2023, 10:59 PM
Last Post: marenr
  Node Flow Generation in Python Linenloid 0 651 Feb-21-2023, 07:09 PM
Last Post: Linenloid
  Flow Control Help RoadToSensei 5 1,676 Feb-14-2022, 08:21 PM
Last Post: deanhystad
  Understanding Raspberry PI RTS/CTS flow control zazas321 2 3,631 Oct-30-2020, 09:55 AM
Last Post: zazas321
  Understanding Raspberry PI RTS/CTS flow control zazas321 0 1,494 Oct-30-2020, 08:02 AM
Last Post: zazas321
  Reproducing assignment with min cost flow in networkx mntfr 0 2,128 Jun-13-2019, 04:06 PM
Last Post: mntfr
  Find Maximum Flow for graph with infinite capacities Dav 6 4,252 Apr-16-2019, 02:08 PM
Last Post: Dav
  Trouble Understanding Why This Code Works crocolicious 2 2,693 Apr-09-2019, 05:24 PM
Last Post: crocolicious
  Python with email forms, and frontend code in general MattH 4 3,392 Feb-18-2018, 03:29 AM
Last Post: MattH
  program flow advice sampazzer 2 3,098 Aug-05-2017, 09:34 PM
Last Post: sampazzer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020