[Solved] Any ideas why this simple code isnt working?

Your problem here is the use of each(). It remembers the index it has reached in the array so in your second loop there is nothing left to loop out so it evaluates to false. If you use reset() this should resolve the issue. while(list($get_key, $get_value) = each($HTTP_GET_VARS)) { if (!${$get_key}) { ${$get_key}=$get_value; } } … Read more

[Solved] Sorting score from text file into average

Use a dictionary with the keys as the class names and the value as a dictionary with student names as the keys and a list to store their scores as the value. Then use the json module to json.dump() the data to a file. When you want to add a new score: json.load() the file, … Read more

[Solved] How to read file on Linux server from Windows?

You will need a SFTP client to read the files. You cant directly replace the path with hostname. You should try something like paramiko for file ready. A quick sample: client= ssh_client.open_sftp() file = sftp_client.open(‘your_filename’) try: for line in file: #Do whatever you want for each line in the file finally: file.close() solved How to … Read more

[Solved] Rearrange the string

Before you do sss+=str;,please add sss=str;. you forget to update your sss. public static void main(String[] args) { String s = “2a[2b[c]]]”; Stack s1 = new Stack(); for(int i=0;i<s.length();i++) { s1.push(s.charAt(i)); } String str=””; String sss=””; for(int j=0;j<s.length();j++) { char a = (char)s1.pop(); System.out.println(“a:”+a); // if(a == ”) if((int)a >=49 && (int)a<=58){ for(int i=0;i<(int)a-48;i++){ sss=str; … Read more

[Solved] count prime number in a list

Here is my fix of your code. def count_primes_in_list(numbers): primes = [] for num in numbers: if num == 2: primes.append(num) else: is_prime = True for i in range(2, num): if num % i == 0: is_prime = False break if is_prime: print (num) primes.append(num) return len(primes) z = [4, 5, 6, 7, 8, 9, … Read more

[Solved] Program is saying all my valid inputs are invalid (REGEX code Issue maybe?) [closed]

I think you need to add Pattern. import java.util.*; public class lab2q2 { public static void main(String[] args) { String RegularExp = “((Mr|Ms))?[A-Z][a-z]+([A-Z]([a-z]+\\.))?([A-Z](a-z)+)”; Pattern pattern = Pattern.compile(RegularExp); Scanner keyboard = new Scanner(System.in); for(int i = 0; i< 11; i++) { System.out.println(“Please enter a name: “); String inputString = keyboard.nextLine(); Matcher matcher = pattern.matcher(inputString ); if(!matcher.matches()) … Read more

[Solved] Java File Handling DisplayOnConsole

c. System.out.println(“Account 1 id 111111 name: john smith balance: 500 $”); System.out.println(“Account 2 id 222222 name: mark smith balance: 1500 $”); System.out.println(“Account 3 id 333333 name: steve jones balance: 2000 $”); System.out.println(“Account 4 id 444444 name: mary jones balance: 1000 $”); If you have the variables data, you can replace each id, name and balance … Read more

[Solved] length of a character pointer not correct using strlen()

The argument a (a pointer) is passed to input() by value. So the change a = regrowchar(a, size) is not visible to main(). Pass it by reference. Also, although you haven’t asked, your code leaks memory, since it dynamically allocates but never deallocates. by https://stackoverflow.com/users/4706785/peter 2 solved length of a character pointer not correct using … Read more

[Solved] Streamreading text files

You are mistaken to think it is reading the first line. In fact, your current code reads the first value of each line. Due to your input this just happens to be a similar output to what the first line would be, which has lead to your confusion. Your main loop should be looping through … Read more

[Solved] How do I make each line from a file list into separate variables?

first, read the file into a string line by line; then convert the string to a variable. In python, you can do the following i = 0 with open(“file.txt”, “r”) as ins: v = “var”+str(i) for line in ins: exec(v+”=’str(line)'”) i+=1 another approach is to read the lines into a list: with open(“file_name.txt”, “r”) as … Read more

[Solved] How can i simplify these if-statements?

One thing that seems obvious is that you cannot reduce the number of String messages. However, you can still remove the clutter by replacing consecutive System.out.println statements with a single System.out.println statement as follows : Your code : System.out.println(specialWelcome1); System.out.println(joinLogin1); Formatted code : System.out.println(specialWelcome1 +”\n”+joinLogin1); The above formatted code can look ugly for cases where … Read more